Home > Mobile >  How do I automate cmd commands to run flask server
How do I automate cmd commands to run flask server

Time:07-29

Every time I start working on my Flask project I need to run these commands in cmd:

cd myproject
venv\scripts\activate
set FLASK_APP=project
set FLASK_ENV=development
flask run --host=0.0.0.0

Is there a way to make a batch file that would execute these commands?

CodePudding user response:

I think something like this could help you. Open notepad and write the following:

@ECHO OFF
CALL venv\scripts\activate
set FLASK_APP=project
set FLASK_ENV=development
flask run --host=0.0.0.0

Save this as run.bat inside your myproject directory. Then you can call this new script.

CodePudding user response:

The following code may help you:

create init.py in your app folder (project):

from flask import Flask

def create_app():
    app = Flask(__name__)
    # configure the app here

    return app

then create run.py

from project import create_app

app = create_app()
if __name__ == "__main__":
    app.run(host="0.0.0.0", port="5000", debug=True, use_reloader=True)

then all you have to do is type python run.py an there you go. (make sure you're in virtual environment)

  • Related