Python Flask Basics Welcome to Flask Request args

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

def index(name="Treehouse"):
    return 'Hello {}'.format('name')
Seth Kroger
Seth Kroger
56,377 Points

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

1 Answer

John Lack-Wilson
John Lack-Wilson
8,164 Points

The 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__)

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'.