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 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 68,457 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)