I have this from /home/myname/myapp/app.py :
from flask import Flask app = Flask(__name__) print __name__ @app.route('/') def index(): return "Hello world!" if __name__ == '__main__': print 'in if' app.run()
When I run:
$ gunicorn app:app -b 127.0.0.2:8000
It says:
2013-03-01 11:26:56 [21907] [INFO] Starting gunicorn 0.17.2 2013-03-01 11:26:56 [21907] [INFO] Listening at: http:
So the __name__ app is app . Not __main__ , as I need to run the if statement.
I tried putting an empty __init__.py into the directory. Here is my nginx sites-enabled default :
server { #listen 80; ## listen for ipv4; this line is default and implied #listen [::]:80 default_server ipv6only=on; ## listen for ipv6 root /home/myname/myapp; # Make site accessible from http:
Edit
... While this application
is printing
'Hello world' when visiting the site. The thing is, I need
__name__ to equal
'__main__' . I also just want to know why this is not so and how to make it equal to
__main__ .
Edit 2
... I just had the epiphany that I did not need to run
app.run() , since this requires Gunicorn. Duh. But I still would like to find out why
__name__ not
'__main__'
source share