1. Custom command
2. Multi-Application app
3.wtforms certification
4.sqlalchemy Introduction
5.scoped_session
6. Table Single Operation
7. many relationship
8. many relationship
9.flask-sqlalche
A Custom Command
Django similar in python3 manage.py runserver .... Similar commands are used to achieve
First introduced flask-script
# The first step to install: install the Flask PIP3-Script # implementation: Python install flask-script.py the runserver from the Flask Import the Flask from flask_script Import Manager App = the Flask ( __name__ ) Manager = Manager (App) @ app.route ( " / " ) DEF index (): return " OK " # custom command @ manager.command DEF custom (Arg, a): " "" If a transmission parameter, print 2 a first embodiment of a custom command python manage.py custom 123 : Arg param: : return: "" " Print (Arg, A) @ manager.option ( ' -n ' , ' --name ' , dest = ' name ' ) @ manager.option ( ' -u ' , ' - -url ' , dest = ' URL ' ) DEF cmd (name, URL): "" " Note: this corresponds to the function decorator inside the parameters, there are several decorator should have several parameters corresponding to a second custom command mode (-n can also be written --name) execute: python manage.py cmd -n lqz -u http://www.oldboyedu.com performs: Python manage.py cmd --name LQZ --url http://www.oldboyedu.com : param name: : param URL: : return: """ print(name, url) if __name__ == '__main__': manager.run()
II. Multi-Application app
from werkzeug.wsgi Import DispatcherMiddleware from werkzeug.serving Import run_simple from Flask Import the Flask App1 = the Flask ( ' app01 ' ) App2 = the Flask ( ' app02 ' ) '' ' has two app url path is the same, how they can be distinguished 2 a, can be configured in one app below a DM = DispatcherMiddleware (app1, { '/ sec12': App2, }) to specify what, in accessing a sec12 preceded it, App2 when access to usual access app1 '' ' app1.route @ ( ' / index ' ) DEF index(): return "app01" @app2.route('/index') def index2(): return "app2" dm = DispatcherMiddleware(app1, { '/sec12': app2, }) if __name__ == "__main__": run_simple('localhost', 5000, dm)
Three .wtforms (form validation)
The first step you need to install: pip3 install wtforms
Four .sqlalchemy Introduction
五.scoped_session
VI. TABLE single operation
VII. To-many relationship
VIII. To-many relationship
九.flask-sqlalche