Base structure for a Flask web app.
- General directory set up.
- Base HTML Templating
- Starter routes for login authorization and error handling
- Initiates Flask extensions: SQLAlchemy, Login Manager, Marshmallow
- Clone the repository.
git clone https://github.com/erikjmurray/FlaskTemplate
- Change into the project directory.
cd your_project_directory
- Install dependencies.
pip install -r requirement.txt
Note that you may need to use a variation of the following command if you have not properly added Python to your environment path.
python -m pip ...
py -m pip ...
To use the setup a Flask app, follow these steps:
- Create a
.env
file in the instance directory in the format below.
FLASK_SQLALCHEMY_DATABASE_URI='sqlite:///test.db' # on first run, test.db file will be created in this folder.
FLASK_SQLALCHEMY_TRACK_MODIFICATIONS=false # removes deprecated error messaging from Flask
FLASK_SECRET_KEY = 'secret' # generated by app if not present on first run
FLASK_ENCRYPTION_KEY = 'super_secret' # generated by app if not present on first run
FLASK_DEBUG=true # For use in production only. Adds error messages to terminal
FLASK_YOUR_SETTING = 'setting' # will be added to the app.config file
- Note: While you can manually add secret key or encryption key to the .env, they will be crytopgraphical generated on first run if not present.
- Also please reference the Flask documentation for linking to any other databases such as MySQL or PostGRES. This setup will create a local database named test in the /instances directory
- The app automatically adds anything prefixed with FLASK_ to the global namespace of the app. You can therefore add any additional settings to the application using the prefix FLASK_ then the name of your variable for example FLASK_YOUR_SETTING. These variable can be referenced in any route using the:
current_app.config['YOUR_SETTING']
dict call - These settings will only load when the app is started. If any changes are made to the .env while the app is running they need to also be added to the app.config to be referenced in the app without restarting.
- Run the Flask app.
python app.py
# OR
flask run
Feel free to customize the configuration and adapt the code to your specific requirements.
Feel free to modify the sections, add more details, or customize the README.md
file further according to your project's specific needs.