当前位置:网站首页>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>
边栏推荐
- CocosCreator事件派發使用
- Cocoscreator event dispatch use
- [test development] software testing - Basics
- Flask 轻量web框架
- What if Kaili can't input Chinese???
- Perfectly integrated into win11 style, Microsoft's new onedrive client is the first to see
- Load test practice of pingcode performance test
- 无心剑中译伊丽莎白·毕肖普《一门技艺》
- About the pit of firewall opening 8848 when Nacos is started
- regular expression
猜你喜欢
Talk about seven ways to realize asynchronous programming
[unity ugui] scrollrect dynamically scales the grid size and automatically locates the middle grid
《吐血整理》保姆级系列教程-玩转Fiddler抓包教程(2)-初识Fiddler让你理性认识一下
整理混乱的头文件,我用include what you use
解读数据安全治理能力评估框架2.0,第四批DSG评估征集中
With an annual income of more than 8 million, he has five full-time jobs. He still has time to play games
leetcode:421. The maximum XOR value of two numbers in the array
The Block:USDD增长势头强劲
CocosCreator事件派發使用
detectron2安装方法
随机推荐
大规模服务异常日志检索
To sort out messy header files, I use include what you use
High school physics: force, object and balance
Datakit -- the real unified observability agent
Cocoscreator event dispatch use
无心剑中译伊丽莎白·毕肖普《一门技艺》
Win32 API 访问路由的加密网页
Firewall basic transparent mode deployment and dual machine hot standby
Wuzhicms code audit
第十八届IET交直流输电国际会议(ACDC2022)于线上成功举办
【HCIA持续更新】WLAN工作流程概述
一加10 Pro和iPhone 13怎么选?
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"
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.
Recast of recastnavigation
【HCIA持续更新】WLAN概述与基本概念
超标量处理器设计 姚永斌 第7章 寄存器重命名 摘录
电子宠物小狗-内部结构是什么?
NFT liquidity market security issues occur frequently - Analysis of the black incident of NFT trading platform quixotic
Interpretation of data security governance capability evaluation framework 2.0, the fourth batch of DSG evaluation collection