KexAri KexAri - 1 year ago 65
Python Question

I don't need the run() method in a Flask application?

I have a Flask application setup on my linode with a directory structure like so:



from flask import Flask
from main import main
app = Flask(__name__)

like so:

from flask import Blueprint

main = Blueprint('main',__name__)
def hello():
return "Hello World!"

def england():
return "Hello England!"

If I run the app locally there are no issues. If I go to my server address in the web browser I get an internal server error. However if I remove the line:
it works fine. Why is this? Why do I not need the run method?

Answer Source

You should do

if __name__ == '__main__':

The reason is that Apache or NGINX or some other web server loads your app directly on the server but runs flask's internal web-server so you can test your app.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download