Forums

New at flask deployment

Hello I am new to python and trying to deploy a small flask app that is working on my local environment. The app has a flask program inside of a .py file, and it serves up an HTML , and has a "/" route and one other route. It is a simple app with no database.

I'm trying to run these commands on the "Web" version of my flask app that's hosted on pythonanywhere.com

When I run this command in the bash console provided by pythonanywhere in mysite directory that is holding my flask_app.py file

pip install -r requirements.txt

(i'm not even 100% sure this is what I'm supposed to do.) I get this error:

Address already in use
Port 5000 is in use by another program. Either identify and stop that program, or start the server with a different port.

Can someone help me figure out how to get my simple app running? I'm very new to everything so please let me know the details I am leaving out.

Have a look at this help page on how to set up a flask app on PythonAnywhere.

Hey not sure if you got a solution to this yet but you can use something like this to change the port at startup:

    import random as rd
    if __name__ == "__main__":
        rand_port = rd.randint(5000, 9999)
        app.run(debug=False)

ApparentltĀ”y macOS 12 and up runs the AirPlay receiver on port 5000 by default. You can disable that per this guide but it shouldn't be necessary.

These links helped me get squared away Basic setup WSGI file

As per this help page, you can't use app.run on PythonAnywhere, you need to deploy the app via the Web page.