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

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.