Skip to content

Instantly share code, notes, and snippets.

@sohang3112
Created March 21, 2023 05:28
Show Gist options
  • Save sohang3112/cc61efb3c9dc7de061fd5dab37ec45d2 to your computer and use it in GitHub Desktop.
Save sohang3112/cc61efb3c9dc7de061fd5dab37ec45d2 to your computer and use it in GitHub Desktop.
Notes on Flask (Python Web Server library)

Flask

Note: Before running any of the mentioned CLI commands, be sure to cd to your project's root directory.

Running a Flask server app

By default, Flask:

  • expects your server code in app.py or wsgi.py,
  • runs on port 5000, and
  • does not run in debug mode.

If you're ok with these defaults, then you can simply do flask run to start the server.

You can also run with some different settings like this:

flask --app my_flask_app.py --debug run --host 0.0.0.0 --port 6000

This command works for flask>=2.2 - for older Flask versions, do this instead:

FLASK_APP=my_flask_app.py FLASK_DEBUG=1 flask run --host 0.0.0.0 --port 6000

You can also start the Flask server directly in your Python code like this:

from flask import Flask

app = Flask(__name__)
# Add some router endpoints here...

# app.run()                                         # Run with default settings
app.run(host='0.0.0.0', port=5000, debug=True)     
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment