The initial experience of the process of Flask Development
From flask import Flask
From flask_script import Manager
From flask_migrate import Migrate,MigrateCommand
From flask_sqlalchemy import SQLAlchemy
From flask_wtf.csrf import CSRFProtect
From flask_session import Session
Import redis
App= Flask (_ _ name__)
Manager = Manager (app)
Db = SQLAlchemy (app)
Class MyConfig (object):
DEBUG = True
# configure SECRET_KEY
SECRET_KEY = "EjpNVSNQTyGi1VvWECj9TvC/+kq3oujee2kTfQUs8yCM6xX9Yjq52v54g+HVoknA"
# configuration information of the database
SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/flask_job_project"
SQLALCHEMY_TRACK_MODIFICATIONS = False
# configure constant
REDIS_HOST = '127.0.0.1'
REDIS_PORT = 6379
# configuration information of flask_session
SESSION_TYPE = "redis" # specifies that session is saved to redis
SESSION_USE_SIGNER = True # Let the session_id in cookie be encrypted and signed
SESSION_REDIS = redis.StrictRedis (host=REDIS_HOST, port=REDIS_PORT) # instances that use redis
PERMANENT_SESSION_LIFETIME = 86400 # session validity period (in seconds)
App.config.from_object (MyConfig)
# enable csrf protection
CSRFProtect (app)
# for database migration
Migrate (app, db)
Manager.add_command ('db',MigrateCommand)
# configure redis
Redis_store = redis.StrictRedis (host=MyConfig.REDIS_HOST, port=MyConfig.REDIS_PORT)
# configure Session
Session (app)
If _ _ name__ = ='_ _ main__':
# app.run ()
Manager.run ()