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

mike henning
mike henning
1,384 Points

3 of 3 explain

from flask import Flask

app = Flask(__name__)

def hello(name="treehouse"):
     return 'Hello {}' .format(name)

I need help understanding why now an argument is now just adding a string inside

Def hello(name=“treehouse”):


Name= request.args.get(name,”treehouse”)

1 Answer

Chris Freeman
Chris Freeman
Treehouse Moderator 68,029 Points

Hey mike henning, good question.

Once the route ’/<name>’ is added, the function needs to accept an argument from this route. So (name) is added.

However, since the original route ’/‘ is still valid, this will cause an error because this original route will call the function with no arguments when one is now required.

To prevent this missing argument error, a default is defined: (name=“treehouse”)

So, effectively, the route / is automatically turned into /treehouse.

Post back if you need more help. Good luck!!!