This is meant to be a quick jumping point for starting new Flask projects. You should be able to fork the repo, make a few changes and be ready for deployment to Heroku within a few minutes.
- Python 3.6.x
- Flask 0.12
- MongoDB 3.x
- Flask-Login
- Flask-MongoEngine
- Flask-WTF
- Flask-DebugToolbar (Dev only)
- Flask-Testing (Dev only)
Ensure you have MongoDB installed. On Mac, thats super easy with Homebrew:
brew install mongodb
Then create your environment and run the project:
$ virtualenv -p `which python3` env
$ . env/bin/activate
$(env) make setup
$(env) make run
An admin user can be created with:
make superuser
Models are created using MongoEngine and are put into
their own module in the app/models/
directory.
The models to be loaded at runtime must be specified in the MODELS
config.
By default, this is located in the config/common.py
file. The name must match
the module file and will be loaded in the order specified.
Example:
MODELS = ('user', 'post', 'comment')
Flask "views" in the form of Blueprints are loaded at runtime. To learn more about Blueprints, you can read the official Flask docs.
Each Blueprint should exist in its own file and have the variable bp
available
as the Blueprint instance.
The Blueprints are loaded automatically based on the BLUEPRINTS
config found
in the config/common.py
module.
Example config:
BLUEPRINTS = ('main', 'user', 'admin')
Example Blueprint
bp = Blueprint('main', __name__)
@bp.route('/')
def index():
return render_template('index.html')
Extensions are also loaded at runtime and can be any module with a setup
function. This is often used to configure other Flask extensions or custom tools
that need the app instance.
The extensions are loaded automatically based on the EXTENSIONS
config found
in the config/common.py
module.
Linting and tests are highly encouraged. To run them, use:
make quality
You can also run tests without linting with:
make test
And lint without testing using:
make lint
app/
Flask project rootapp/forms/
Form definitions for WTFormapp/extensions/
Modules for automatically setting up extensions at run timeapp/models/
MongoEngine modelsapp/static/
Static assets such as CSS, JS etc.app/templates/
Jinja HTML templatesapp/views/
Flask Blueprints (routes)app/__init__.py
Flask app entry pointconfig/
All configs hereconfig/common.py
Configs to be used across all environmentsconfig/local.py
Configs specific to local developmentconfig/production.py
Configs specific to productionconfig/test.py
Configs specific to testing