Flask Web Development Road 14

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.