Start flask Today, create a project that includes user login, registration, logout, blog, comment, and search functions.
First give the project structure:
1.config.py file:
Store various configuration information
ImportOS#Dialect+driver://username:[email protected]:p ort/databasedialect ='MySQL'DRIVER='Pymysql'USERNAME=' User name'PASSWORD=' Password'HOST=' Domain name'PORT=' Port number'DATABASE=' Database name'Sqlalchemy_database_uri="{}+{}://{}:{}@{}:{}/{}?charset=utf8". Format (dialect,driver,username,password,host,port,database) sqlalchemy_track_modifications=Falsedebug=Truesecret_key= Os.urandom (#用于生成session密钥)
2.decorators.py file holds the adorner that restricts the login, and then mentions that the 3.exts.py file holds the database instantiation object
from Import = SQLAlchemy ()
4.hyqbook.py main app file 5.manage.py file, which contains a series of code for Command Line window operation, including database initialization, database migration, database update, etc.
fromFlask_scriptImportManager fromFlask_migrateImportMigrate,migratecommand fromHyqbookImportapp fromExtsImportDB fromModelsImportUser,question,answermanager=Manager (APP)#use migrate to bind apps and DBMigrate =Migrate (app,db)#Add a Migration script command to the managerManager.add_command ('DB', Migratecommand)if __name__=="__main__": Manager.run ()
5.models.. PY file, storing the data model
Flask web Development Route 14