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 Variables

Paul Bentham
Paul Bentham
24,090 Points

I've put in exactly as per the video on the challenge but it's coming up with an error? is there a bug in this?

My code is as below: from flask import Flask from flask import request

app = Flask(__name__)

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

3 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

You have requests on your name= line. You probably want request (no "s").

Paul Bentham
Paul Bentham
24,090 Points

Thanks Kenneth! (always the little things that catch us out)

from flask import Flask
from flask import request

app = Flask(__name__)

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

I input this in the challenge and it still doesnt work.

I get the response " Bummer! '/' gave a non-200 response. Did you change the route?" Any idea whats wrong?

Adrian Wisaksana
Adrian Wisaksana
8,070 Points

Instead of having

return "Hello {name}".format(name)

I think it should just be

return "Hello {}".format(name)

Hope that helps!

or

return "Hello {name}".format(name=name)

using .format method with kwargs. Maybe not the most conventional way but that's how I did it.

william parrish
william parrish
13,774 Points

Which challenge is it, what are they asking you to do?

Paul Bentham
Paul Bentham
24,090 Points

It's in the flask basics course, the "request args" challenge.