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 Create a view

Add a view function named index. Give this view a route of "/". Make the view return your name. Help ? Anyone?

Can anybody tell me where Im going wrong with my code ? Im so confused!

flask_app.py
from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World!'

if __name__ == '__main__':
    app.run()

4 Answers

you only need to write a function just like the hello_world but returning your name.

The view is the function you write right after the @app.route('/') decorator

ok thank you!!!! However when do that I get an error "Bummer/ non 200 response" so I thought I had to add something extra ... like a kwargs function or something?

abdulkadir yıldız
abdulkadir yıldız
2,711 Points
from flask import Flask

app = Flask(__name__)

@app.route("/")
def index():
    return __name__

ok thanks i got it!!! your a star! was looking at it wrong for ages!

Hi Shannon

the problem is you have named your view 'hello_world' rather than index. Also return your name and not hello world, ohh one more thing you don't need the app.run()

Thank you Andreas!!!