Python Flask Basics Welcome to Flask Request Variables

Paul Bentham
Paul Bentham
22,454 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
22,454 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
22,454 Points

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