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 View Args Through URL

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

Why is this code not passing challenge Challenge Task 2 of 3 from Flask Basics: from flask import Flask. I get a "Bummer! '/' without a name gave a non-200 response."

flask_app.py
from flask import Flask

app = Flask(__name__)

@app.route('/<name>')
def hello(name="Treehouse"):
     return 'Hello %s' % name

5 Answers

Hanley Chan
Hanley Chan
27,771 Points

Hi,

Step 1 asks to add a new route to hello() instead of overwriting the default. It should work if you put the route back in.

@app.route('/')

Thanks, makes sense now. And it worked.

from flask import Flask

app = Flask(__name__)


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

This is how it should look

from flask import Flask from flask import request

app = Flask(name)

@app.route('/') def index('name'='treehouse'): name = request.args.get('name',name) return "Hello {}".format(name)

shawn Jones
shawn Jones
5,960 Points

I'm stuck id did everything and no response from flask import Flask from flask import request app = Flask(name)

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

hi martin it asks you to add a default route.

from flask import Flask

app = Flask(__name__)

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

Thanks.