Giter VIP home page Giter VIP logo

cookiecutter-flask's Introduction

Cookiecutter for flask

Build Status

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.

Currently integrated:

  • 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

Not (yet) integrated

  • Frontend-Framework
  • Asset-Bundler
  • Caching
  • wsgi-server

Installation and basic Usage

Note: cookiecutter-flask is currently only tested under python 3.5!

1. Install cookiecutter

pip install cookiecutter

2. Clone cookiecutter-flask

cookiecutter https://github.com/on3iro/cookiecutter-flask.git

3. Preparation

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.

4. Install Requirements

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

5. Project initialisation

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

6. Working with cookiecutter-flask

Running the server

./manage.py server

Testing the application

./manage.py test

Generating test coverage information

py.test --cov=<app_name> --cov-report=html

(This will probably become a manage.py command as well in the future)

Migrating the database

./manage.py migrate
./manage.py upgrade

(Note that it is advised to check migrations before upgrading!)

7. Create documentation

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

Initial routes

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.