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 trialJack Chimvumbo
4,161 PointsFlask Basics
Challenge Task 1 of 1
Import request from Flask. Then update the index view to return "Hello {name}", replacing {name} with a name argument in the query string.
from flask import Flask
from flask import request
app = Flask(__name__)
@app.route('/')
@app.route('/<name>')
def index(name="Treehouse"):
return 'Hello {}'.format('name')
1 Answer
John Lack-Wilson
8,181 PointsThe challenge is asking you to use Flask's request module to get the name argument from the URL query string.
I feel it may be easier to explain this and be more understandable by providing the successful code below:
from flask import Flask, request
app = Flask(__name__)
app.route('/')
def index():
return 'Hello ' + request.args['name']
We can simply have one @app.route() declaration here, as we are going to request additional information from the URL. This is achieved using the .args function which asks for the 'name' part of the URL, and of course this is concatenated with 'Hello'.
Seth Kroger
56,413 PointsSeth Kroger
56,413 PointsI don't know Flask so I can't tell you if you have the query part down. However, format usual takes variables but the single quotes makes it a literal string. I would first remove them, i.e.,
format(name)
.