当前位置:网站首页>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>
边栏推荐
- 《吐血整理》保姆级系列教程-玩转Fiddler抓包教程(2)-初识Fiddler让你理性认识一下
- Two methods of MD5 encryption
- CocosCreator事件派发使用
- 电子宠物小狗-内部结构是什么?
- What grade does Anxin securities belong to? Is it safe to open an account
- The Block:USDD增长势头强劲
- Easy to use map visualization
- 超标量处理器设计 姚永斌 第6章 指令解码 摘录
- With an annual income of more than 8 million, he has five full-time jobs. He still has time to play games
- Dynamic programming stock problem comparison
猜你喜欢
Recast of recastnavigation
第十八届IET交直流輸電國際會議(ACDC2022)於線上成功舉辦
Talk about seven ways to realize asynchronous programming
7 RSA密码体制
Wuzhicms code audit
Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing
Zebras are recognized as dogs, and the reason for AI's mistakes is found by Stanford
《吐血整理》保姆级系列教程-玩转Fiddler抓包教程(2)-初识Fiddler让你理性认识一下
要上市的威马,依然给不了百度信心
Perfectly integrated into win11 style, Microsoft's new onedrive client is the first to see
随机推荐
RecastNavigation 之 Recast
Leetcode list summary
The Ministry of human resources and Social Security announced the new construction occupation
Vb无法访问数据库stocks
Is it safe for Great Wall Securities to open an account? How to open a securities account
VB cannot access database stocks
将Opencv绘制图片显示在MFC Picture Control控件上
Win32 API 访问路由的加密网页
Recast of recastnavigation
Ble HCI flow control mechanism
wuzhicms代码审计
I2C子系统之适配器的设备接口分析(i2c-dev.c文件分析)
Zebras are recognized as dogs, and the reason for AI's mistakes is found by Stanford
PingCode 性能测试之负载测试实践
Ks007 realizes personal blog system based on JSP
【Hot100】31. 下一个排列
斑马识别成狗,AI犯错的原因被斯坦福找到了丨开源
无心剑中译伊丽莎白·毕肖普《一门技艺》
Is BigDecimal safe to calculate the amount? Look at these five pits~~
Solution of dealer collaboration system in building materials industry: empowering enterprises to build core competitiveness