Skip to content

baichen99/flask_app_example

Repository files navigation

flask file structure

Usage

create .env file, edit the file as follows.

# .env
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD=123456
MYSQL_DB=rest
python manage.py initdb
python manage.py init-user
flask run

test

python manage.py test

RESTful

Use flask_restful framework to implement RESTful style api

Serializer

This essay introduce how to use Marshmallow library to serialize and deserialize.

marshmallow is an object serialization/deserialization library, you can use it to format your response ouput and to validate form fields in an easy way.

Settings

Use Flask.config.from_object set config from an ojbect, and to better manage environment variables, I use python-dotenv to load env variables from .env file.

Databases

flask_sqlalchemy is an extension for Flask that adds support for SQLAlchemy to your application. It aims to simplify using SQLAlchemy with Flask by providing useful defaults and extra helpers that make it easier to accomplish common tasks.

JWT

Flask-JWT-Extended’s Documentation

How to use jwt in flask

difference between refresh token and access token

Unittest

Unit testing framework flask test 【Flask 教學】實作 Flask 單元測試 Unit Test

Custom error handler

flask-restful-custom-error-handling

Questions

  1. Access a Flask extension that is defined in the app factory
  2. circular dependency problem

Inspiration

jinlygenius/flask_structure_example

todo

  • i18n
  • cors
  • middlewares

About

A flask project structure

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages