当前位置:网站首页>Flask lightweight web framework
Flask lightweight web framework
2022-07-04 17:45:00 【Wu_ Candy】
【 precondition : You are already in windows It's finished Pycharm Integrated development tools +python3.6 Version of and related third-party packages 】
Step1: Go directly to the full picture of the frame
Step2: Structural description of the frame
Project structure
- manage.py Used to control the program python manage.py runserver # Start service command python manage.py shell # Get into shell Script mode commands - app/__init__ Initialization file Initialize the whole Flask object , as well as Flask Various plug-ins used , And return a app application - app/settings Project profile Configure the entire project operation environment - app/ext Extension library of the project Third party extension library packaging - app/views The view function Process business logic Coordinate the relationship between modules and models - app/models Model Define the model structure Get the relational mapping of the tables in the database db.create_all() Create database db.drop_all() Delete database - doc Framework description document - static Directory for storing static resources - templates The directory used to store template resources - migrations Migration Directory
Data migration
- Map the model to the database - Use flask-migrate library - Installation and use pip install flask-migrate initialization , Need to use app and db To initialize ,migrate=Migrate(app,db) To configure flask-script The order of manager.add_command('db',MigrateCommand)
- Instructions to use python manage.py db init init Initialization instruction , Can only be called once python manage.py db migrate migrate Instructions are used to generate migration files Internal migration files use linked lists to associate relationships --message MSG Add log description for migration python manage.py db upgrade upgrade Instructions are used to execute migration files Database content upgrade python manage.py db downgrade downgrade Instructions are used to execute migration files Database content degradation , Equivalent to regret medicine
- help Help document
Step3: The general call logic is as follows
<1> App/views.py The file introduces models.py【 Model objects in the model package 】andext.py【 In the expansion package db object 】
<2> App/__init__.py The file introduces views.py【 The blueprint in the view package 】,ext.py【 Introduce the expansion package and do initialization work in the expansion package 】,settings.py【 Introduce the setting package and do the database connection, environment configuration and resource directory settings 】. Finally, initialization is completed app After the application , Return to one app application .
<3> manage.py It's the entry file , Get the one returned in the previous step app application , Finally, start the service .
Step4: After the service is started, the effect of visiting the home page is
Step5: For the above figure, see the source code of routing and page
In fact, it is to render Templates/home.html page
App/views.py:
@blue.route('/index/',methods=['GET','POST']) def index(): return render_template('home.html')
The page is mainly the two links of login and exit
Templates/home.html The page source code is :
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <h2>welcome back:{{ username }}</h2> <a href="{{ url_for('second_blue.login') }}">login</a> <a href="{{ url_for('second_blue.logout') }}">logout</a> </body> <html>
边栏推荐
- 【系统分析师之路】第七章 复盘系统设计(结构化开发方法)
- Load test practice of pingcode performance test
- 【HCIA持续更新】WLAN工作流程概述
- 什么是低代码开发?
- Is it safe for Great Wall Securities to open an account? How to open a securities account
- Talk about seven ways to realize asynchronous programming
- Cocoscreator event dispatch use
- Dynamic programming stock problem comparison
- 超大规模数仓集群在大型商业银行的落地实践
- 【模板】【luogu P4630】Duathlon 铁人两项(圆方树)
猜你喜欢
La 18e Conférence internationale de l'IET sur le transport d'électricité en courant alternatif et en courant continu (acdc2022) s'est tenue avec succès en ligne.
Difference between redis' memory obsolescence strategy and expiration deletion strategy
CocosCreator事件派发使用
PingCode 性能测试之负载测试实践
How to choose one plus 10 pro and iPhone 13?
电子宠物小狗-内部结构是什么?
要上市的威马,依然给不了百度信心
第十八届IET交直流输电国际会议(ACDC2022)于线上成功举办
解决el-input输入框.number数字输入问题,去掉type=“number“后面箭头问题也可以用这种方法代替
Zhijieyun - meta universe comprehensive solution service provider
随机推荐
La 18e Conférence internationale de l'IET sur le transport d'électricité en courant alternatif et en courant continu (acdc2022) s'est tenue avec succès en ligne.
[Huawei HCIA continuous update] SDN and FVC
【Unity UGUI】ScrollRect 动态缩放格子大小,自动定位到中间的格子
你应该懂些CI/CD
The Block:USDD增长势头强劲
补能的争议路线:快充会走向大一统吗?
Detectron2 installation method
超大规模数仓集群在大型商业银行的落地实践
国产数据库TiDB初体验:简单易用,快速上手
To sort out messy header files, I use include what you use
如何进行MDM的产品测试
[unity ugui] scrollrect dynamically scales the grid size and automatically locates the middle grid
Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing
Solve the El input input box For number number input problem, this method can also be used to replace the problem of removing the arrow after type= "number"
What are cache penetration, cache breakdown, and cache avalanche
wuzhicms代码审计
【HCIA持续更新】WLAN概述与基本概念
Interpretation of data security governance capability evaluation framework 2.0, the fourth batch of DSG evaluation collection
ble HCI 流控机制
VSCode修改缩进不成功,一保存就缩进四个空格