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 trialJonathan Musso
3,760 PointsFlask: Add a new route to hello() that expects a name argument. The view will need to accept a name argument, too.
Hey all. I have been having a lot of trouble with the editor and Workspace on Chrome for Win 8.
The last few live quiz I tested in my Workspace and they worked but the quiz did not accept the answer after a few tries...not sure what's going on. It's difficult to see if I am doing the code right or wrong.
Anyway here is my code, is this right?
from flask import Flask
app = Flask(__name__)
@app.route('/')
@app.route('/hello/<name>')
def hello():
return 'Hello {}'.format(name)
4 Answers
John Sanchez
3,325 PointsYou want to use __name__
to pass in for the app object, since it refers to the namespace. Name should be the parameter for the hello() view.
def hello(name):
Bo Yuan
20,928 Pointsfrom flask import Flask
app = Flask(__name__)
@app.route('/')
@app.route('/<name>')
def hello(name):
return 'Hello Student {}'.format(name)
Andrew Winkler
37,739 PointsWell, this code answers question one and sort of goes into answering question 2...
John Sanchez
3,325 PointsThey don't want the second route at python
/hello/<name>
, just at python /<name>
. The hello() in the problem description refers to the view name that you are adding the route to.
Also, you need to make sure to add name as a parameter to the view, as per: "The view will need to accept a name argument, too."
Jonathan Musso
3,760 PointsJohn,
Thanks for the info.
So what am I doing wrong with the parameter here?
from flask import Flask
app = Flask(__name__)
@app.route('/<name>')
def hello():
return 'Hello {}'.format('name')
Kenneth Love
Treehouse Guest TeacherYour view still doesn't take a name
argument. The view is a function that has a route. So it should be hello(name)
, not just hello()
. Also, you were supposed to add a new route that expects a name. The hello()
view should have two routes by this point.
Jonathan Musso
3,760 PointsKenneth thanks for the explanation. I started my first answer with this and was receiving errors that my first exercise was broken. When I made a new browser window and entered the same information it worked..
alex faroro
895 Pointsfrom flask import Flask
app = Flask(name)
@app.route('/')
@app.route('/<name>')
def hello(name): return 'Hello Student {}'.format(name)
Jonathan Musso
3,760 PointsJonathan Musso
3,760 PointsThank you. This make sense, so before I was trying to call the variable that had no parameters defined..!