This is a simple cookiecutter for flask. It is still a work in progress, but should work fine already. I drew a lot of inspiration from slorias cookiecutter.
- Password hashing via Flask-Bcrypt
- bpython shell
- Testing with pytest, WebTest and pytest-flask
- Test coverage via coverage and pytest-cov
- Flask-Admin
- Flask-DebugToolbar
- Login management with Flask-Login
- Database migrations via Flask-Migrate
- Flask-SQLAlchemy
- Formhandling with Flask-WTF
- psycopg2 for postgre connections
- simple login and user registration
- sphinx for documentation
- Frontend-Framework
- Asset-Bundler
- Caching
- wsgi-server
Note: cookiecutter-flask is currently only tested under python 3.5!
pip install cookiecutter
cookiecutter https://github.com/on3iro/cookiecutter-flask.git
I would recommend to take a few seconds and initialize a git repository inside
the newly created cookiecutter. Then go on and create a virtualenvironment
(e.g with pyvenv or virtualenvwrapper). For use in production some settings need
to be made available to flask (e.g. the secret key). Check those lines which
are marked with a TODO
-command inside settings.py. The secret key for
example can be stored inside an environment variable.
To store your environment variable inside the virtualenvironment just add
lines like the following to env/bin/activate:
<YOUR_APP_NAME>_SECRET='extremely_secret_key_you_wont_be_able_to_guess'
export <YOUR_APP_NAME>_SECRET
To quickly generate a secret key you can use open the interactive python shell, and type the following commands:
>> import os
>> os.urandom(24)
Then copy the generated key.
Activate your virtualenvironment with:
source <name_of_your_venv>/bin/activate
Now you need to either install requirements for production or development:
pip install -r requirements/prod.txt
or
pip install -r requirements/dev.txt
To create your database, make an initial migration and create a default admin user, follow these commands:
./manage.py db init
./manage.py db migrate
./manage.py db upgrade
./manage.py create_admin
./manage.py server
./manage.py test
py.test --cov=<app_name> --cov-report=html
(This will probably become a manage.py command as well in the future)
./manage.py migrate
./manage.py upgrade
(Note that it is advised to check migrations before upgrading!)
Simply cd into the doc/
-directory and use these commands:
sphinx-apidoc -f -o source/ ../<YOUR_APP_DIR>
make html
Now you can simply move into the build/html/
-directory and open the index.html file to see your documentation. For further details have a look at the sphinx documentation
For login/logout routes have a look a the respective views.py files.
localhost:5000: index view
localhost:5000/users/: member page (login required)
localhost:5000/users/register: user registration (a newly registered user will be inactiv and has to be activated inside the admin panel!)
localhost:5000/admin/: admin index page (login required, user hast to be an admin)
localhost:5000/admin/user/: admin panel for user model
localhost:5000/admin/role/: admin panel for role model