Flask ORM Framework----------Flask-sqlalchemy Application

Source: Internet
Author: User

definition: The Ask extension encapsulates the SQLAlchemy framework. In Flask-sqlalchemy, the database is specified using a URL, and the following table lists the common database engines and the corresponding URLs.
Installation: Pip Install Flask-sqlalchemy
Pip Install Flask-migrate

# Boot file
fromFlask_scriptImportManager,server fromFlask_migrateImportmigratecommand,migrate fromRbacImportCreate_app,dbapp=Create_app () Manager=Manager (APP) Migrate=Migrate (app,db) Manager.add_command ("Runserver", Server ()) Manager.add_command ("DB", Migratecommand)if __name__=='__main__': Manager.run ()
# Startup file Startup Auto Trigger
fromFlaskImportFlask fromConfig.settingImportBaseconfig#Import Flask-sqlalchemy fromFlask_sqlalchemyImportSqlalchemydb=SQLAlchemy () from. views.userImportUser#Import a table in models from. model.modelsImport*defCreate_app (): App= Flask (__name__) app.register_blueprint (user) Db.init_app (APP)returnApp

Execute command:
First:

Python manage.py DB init
Python manage.py db Migrate
Python manage.py DB Upgrade

II: (view) generate all plugins for the current environment

Generate all dependencies for the current environment: Requirements.txt
PIP3 Freeze > Requirements.txt

Generate all dependencies for the current program: Requirements.txt
PIP3 Install Pipreqs
Pipreqs./

Flask ORM Framework----------Flask-sqlalchemy Application

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.