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

Flask: Replace name with passed in name. What am I doing wrong?

I thought I am defining name in the passed in parameters. This worked in my workspace.

What am I doing incorrectly?

Also, is anyone having trouble with workspaces? I can't view my code anymore.

Cheers,

Jon

flask_app.py
from flask import Flask

app = Flask(__name__)

@app.route('/<name>')
def hello(name="Jon"):

     return "Hello {}".format('name')

3 Answers

Don't provide a default argument for the passed in name. Also, you should have two different routes, one for the original, "/" and one for the new "/<name>"

This is frustrating John. I had both app routes when I first started this, and it told me "exercise 1 is no longer working!"

I just opened a new browser window and started over and it worked.

Should I be clearing my cookies or something? Use another browser? Every exercise I am having problems like this.

By the way, thank you very much for your detailed explanations, much appreciated.

No problem, I'm glad you at least got it to work. I never had that problem with code challenges though -- that seems a bit odd. If it happens again, post your code and the steps you took so I can get a better idea of what is going on.

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

The variable name, and the string 'name', are not the same thing. Your .format() is using the string, so whatever name gets passed in through the URL isn't going to be in the response.