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 First Steps

Natalia Solomkina
Natalia Solomkina
1,594 Points

app.route not working in workspace

In workspace when I add '/newroute' to the address I keep getting 404. The code works fine on my machine though.

from flask import Flask

app = Flask ( __name__ )

@app.route('/newroute')
def index():
  return "Hello from Treehouse"  

app.run(debug=True, port=8000, host='0.0.0.0')

1 Answer

Hasan Ahmad
Hasan Ahmad
6,727 Points

Firstly, you forgot the two dunders (Double underscore) before and after name.

app = Flask(__name__)

Second of all, because the route has a name, in this case its is called '/newroute', you must specify the route in the browser as well.

@app.route('/newroute') 
def index(): 
    return "Hello from Treehouse"

Hope this helps!

  • Hasan
Natalia Solomkina
Natalia Solomkina
1,594 Points

Thanks for the reply! Of course I have dunders, somehow they disappeared after copy-pasting the code. Thank you for noticing, I will edit the question. And sure I add /newroute to the address.