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 args

Flask 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.)

flask_app.py
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
PLUS
William Li
Courses Plus Student 26,868 Points

Hi, larri krown Sooooo closed, only the return String format is off by couple of spaces.

return "Hello {} ".format(name)

Thank you buddy

What'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?

as i see this, one 'name' is the variable from flask/jinja template , second name is the value this variable, but i'm not shure

Yeah, 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.

I 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