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 triallarri krown
1,027 PointsFlask challenge:Didn't get the expected response.
What's wrong in my code? (Challenge is: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('/')
def index(name="Larri"):
name = request.args.get('name', name)
return "Hello{}".format(name)
3 Answers
William Li
Courses Plus Student 26,868 PointsHi, larri krown Sooooo closed, only the return String format is off by couple of spaces.
return "Hello {} ".format(name)
cassac
9,628 PointsWhat's the point of putting both 'name' and name in request.args.get()? I understand the purpose of the second name but the first one in quotation marks, what's the deal with that one?
larri krown
1,027 Pointsas i see this, one 'name' is the variable from flask/jinja template , second name is the value this variable, but i'm not shure
cassac
9,628 PointsYeah, I'm not sure either. But, I believe this isn't the usual convention with Flask as introduced in the next video with variables directly in the URL.
larri krown
1,027 PointsI little confused you, it's exactly variables from the URL
To access parameters submitted in the URL (?key=value) you can use the args attribute:
searchword = request.args.get('key', '')
First 'name' is key from URL which return value, Second name get default value from function param named as name That's how i see it
larri krown
1,027 Pointslarri krown
1,027 PointsThank you buddy