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
Cynthia Lee
8,966 PointsHow @app.route('/') executed the index function? Please explain!
I couldn't understand decorator - @app.route('/'). How it executed the index function? Please explain! Also If i create another function below index function say greet(). The greet does not execute. Why only func below @app.route() is executed?
1 Answer
Julian Garcia
18,380 PointsBasically route tells the server to execute the function under app.route decorator. As far as I know only the function just below the decorator is executed.
This route specify the route in web browser, for example for app.route("/") when you type in web browser 127.0.0.1:8000 you get what the index function returns.
If you want to add to another function a webpage route you just need to add above that function @app.route("/greet")
@app.route("/greet")
def greet():
return "Greetings"
You can access to what greet function returns with:
127.0.0.1:8000/greet
The name of route you specify inside route() is up to you.
Hope this help.