Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Flask Basics Welcome to Flask Clean URL Arguments

Challenge help

Task 2 of 3: "Update the response from hello() to say "Hello {name}", replacing {name} with the passed-in name."

My code:

from flask import Flask

app = Flask(__name__)


@app.route('/<name>')
def hello(name="Wut"):
     return 'Hello {}'.format('name')

gives Bummer! Did you change the view's response?

what am I doing wrong

5 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 67,464 Points

In the View Args Through URL Challenge, the first challange asks:

Add a new route to hello() that expects a name argument. The view will need to accept a name argument, too.

Your code is missing this route from part 1. Updating your code:

from flask import Flask

app = Flask(name)

@app.route('/')
@app.route('/<name>')  # <-- new route
def hello(name="Wut"):
    return 'Hello {}'.format('name')

Challenge Task 2

Update the response from hello() to say "Hello {name}", replacing {name} with the passed-in name.

Your code is very close. The error is in the format. You are formatting a fixed string "name" instead of the passed in name. Remove the quote around name in the format():

from flask import Flask

app = Flask(name)

@app.route('/')
@app.route('/<name>')  # <-- new route
def hello(name="Wut"):
    return 'Hello {}'.format(name)  # <-- removed quotes
Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Why is 'name' quoted in your call of .format()?

Did you complete task 2 of 3? =)

from flask import Flask
from flask import request

app = Flask(__name__)

@app.route('/')
def index(name="Treehouse"):
     return "Hello {}".format(name)

This is 100% correct

Ruby R
Ruby R
1,086 Points

from flask import Flask from flask import request

app = Flask(name)

@app.route('/') @app.route('/<name>') def hello(name): return 'Hello {}'.format(name)