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 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
6,043 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.