Forums

Getting my page up

Im doing a web-app as a school project and I'd like to have the app running online instead of running it just locally The app works when I run the code on my computer, but I cant get it to work on PythonAnywhere Are there any particular commands/steps that I need to make it work?

Im using flask and I think that the solution might be to edit

app.run(host='0.0.0.0', debug=False)

The solution (or at least the first step :-) is actually to not have that line at all. app.run tells Flask to create a web server of its own, but PythonAnywhere provides a web serving environment for you. If you call app.run from inside a PythonAnywhere hosted web app, it will just hang because your code is trying to serve its own website and is never relinquishing control to the PythonAnywhere system.

So, if you can, just remove the app.run line. If you want code that will work on your own computer but also on PythonAnywhere, you can guard it with an if statement that checks whether the web app is being run from a command line, or from inside another application, like this:

if __name__ == "__main__":
    app.run(host='0.0.0.0', debug=False)

Give that a go and let us know how you get on.