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

Python flask error: gaierror: [Errno -2] Name or service not known

this is my code:

from flask import Flask

app = Flask(name)

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

What am i doing wrong??? not sure why im getting the error "Name or service not known" Any suggestions??

1 Answer

I'm not sure if some pieces of your code got transformed or formatted strangely when you pasted it in, but the following should work:

from flask import Flask

app = Flask(__name__)

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

The differences between that and what I see in your question are:

  1. app = Flask(name) should be app = Flask(__name__). __name__ is a special Python variable that needs the double underscores surrounding it.
  2. Formatting for the decorator and the function declaration. Python pays attention to things like line breaks and indentation in your code, so having all that done properly is important to correct code execution.