Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Flask Basics Welcome to Flask Request args

I got the error message: '/' gave a non-200 response. did you change the route? is this a problem with the code?

I have not changed the route, so wondering why I receive this error message. Thanks.

flask_app.py
from flask import Flask
from flask import request

app = Flask(__name__)

@app.route('/')
def index():
    name = request.args.get('name', name)
    return 'Hello {}'.format(name)

2 Answers

I think the error is because you are passing a second argument to request.args.get(). I think it should just be:

 name = request.args.get('name')

Goodluck! --Ricky

perfect. thanks.

So why do we use

request.args.get('name', name)

in the class?

I believe the second argument is a default which only kicks in if the request variable is empty. It would also need to be declared beforehand. AKA you can't pass in name as the second argument without name having a value EX name="Treehouse" somewhere before it is passed in.

Goodluck! --Ricky

from flask import Flask
from flask import request

app = Flask(__name__)

@app.route('/')
def index(name="Treehouse"):
     return "Hello {}".format(name)

This is 100% correct