Skip to content

Mindinventory/flask-boilerplate-structure

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flask boilerplate



Speed up building your scalable application with this boilerplate which includes the latest python support, and a lot more features like Admin panel, SMTP configuration, LRF flow(Login and Registration), mail authentication, separate settings file for root project configuration, travis integration(CI), alembic (database migrations tool), faker(fake data generator), ORM support(SQLAlchemy), Jinja2 (Template Engine) and it is flexible enough for adding and using other libraries.

Table of content

Standard

-If using standard instructions, Python ≥ 3.6 is required.
-A virtual environment is recommended (like virtualenv==20.4.3).
-pip is required for installing software packages.
-It could be easily adapted to run on MySQL or SQLite, but the default installation instructions below assume the use of PostgreSQL.

Project Structure

FlaskBoilerPlate
   ├── app/
   │    ├── api/
   │    │    ├── v1/
   │    │    │    ├── __init__.py
   │    │    │    ├── routes.py 
   │    │    │    └── views.py     
   │    │    └──  __init__.py
   │    ├── auth/   
   │    │    ├── __init__.py
   │    │    ├── forms.py
   │    │    ├── models.py
   │    │    ├── routes.py
   │    │    └── views.py
   │    ├── static/
   │    │    ├── css/
   │    │    ├── img/
   │    │    └── js/
   │    ├── templates/
   │    │    ├── email/
   │    │    ├── errors/
   │    │    ├── forms/ 
   │    │    ├── layouts/
   │    │    └── pages/ 
   │    ├── toolbox/
   │    │    ├── __init__.py 
   │    │    ├── admin.py
   │    │    └── email.py   
   │    ├── __init__.py
   │    └── seeding.py
   ├── env/
   ├── migrations/
   ├── config.py
   ├── requirements.txt
   ├── run.py
   ├── WSGI.py
   └── README.md

Project Directories

1 . app

Main project directory where all app are created.This contains following files and folder.

  • api

  Contains all api versioning and routes files with signup and login apis.

  • auth

  Contains basic authentication features like signup, login, forgot password and reset password views.

  • static

  Contains the Css, Img and Js files used in your project.

  • templates

  Contains the HTML templates used in your project.

  • toolbox

  Contain files for flask admin and sending emails.

  • init.py

  Main app are register here.

  • seeding.py

  Seeding file for create fake user.

2 . env

Contains environment variables.

3 . migrations

Generates automatically when run database migrations command.

4 . config.py

Contains whole projects configurations.

5 . requirements.txt

File contains all project dependency.

6 . run.py

To run your application.

Features

  • User account sign up, login, password reset, all through asynchronous email confirmation.
  • Flask-WTForms for Form generation
  • Flask-SQLAlchemy with basic User model
  • Easy database migrations with Flask-Migrate
  • Flask-Admin for administrative task
  • PyJWT for JWT token authentication
  • Flask-RESTful for Api versioning
  • Bootstrap 4 for starter templates
  • itsdangerous for generating random tokens for the confirmation emails.
  • Faker used for generating fake user for database

Quick Start

  1. Initialize and activate a virtualenv:
    • for windows
      virtualenv env
      \path\to\env\Scripts\activate
    • for linux
     sudo apt install python3-venv
     python3 -m venv env
     source env/bin/activate
  2. Install the dependencies:
     pip install -r requirements.txt # for windows
     pip3 install -r requirements.txt # for linux
  3. For database configuration in config.py
    POSTGRES = {
     'user': 'postgres',
     'pw': 'password',
     'db': 'my_database',
     'host': 'localhost',
     'port': '5432',
     }
    SQLALCHEMY_DATABASE_URI = 'postgresql://%(user)s:\%(pw)s@%(host)s:%(port)s/%(db)s' % POSTGRES 
  4. Run command for database migration:
     flask db init
     flask db migrate -m "Initial migration."
     flask db upgrade
  5. Run the development server:
    • for windows
     set FLASK_APP=run.py
     set FLASK_ENV=development
     flask run
    • for linux
     export FLASK_APP=run.py
     export FLASK_ENV=development
     flask run
  6. Navigate to http://localhost:5000

  7. Generate fake user:
     flask seeder --count=n # here n is number of user
  8. SMTP configuration:

On successful running of the project

home.gif