当前位置:网站首页>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>
边栏推荐
- 【HCIA持续更新】广域网技术
- 正则表达式
- Using win10 scheduling task program to automatically run jar package at fixed time
- Cocoscreator event dispatch use
- 长城证券开户安全吗 证券账户怎么开通
- R language plot visualization: plot visualization of multiple variable violin plot in R with plot
- gatling 之性能测试
- curl 命令妙用
- 第十八届IET交直流輸電國際會議(ACDC2022)於線上成功舉辦
- 如何进行MDM的产品测试
猜你喜欢
第十八届IET交直流输电国际会议(ACDC2022)于线上成功举办
To sort out messy header files, I use include what you use
[HCIA continuous update] WLAN overview and basic concepts
【HCIA持续更新】WLAN概述与基本概念
PingCode 性能测试之负载测试实践
雨量预警广播自动化数据平台BWII 型广播预警监测仪
聊聊异步编程的 7 种实现方式
Cocoscreator event dispatch use
detectron2安装方法
超标量处理器设计 姚永斌 第5章 指令集体系 摘录
随机推荐
Implementation of super large-scale warehouse clusters in large commercial banks
The Ministry of human resources and Social Security announced the new construction occupation
CocosCreator事件派發使用
创业两年,一家小VC的自我反思
国产数据库TiDB初体验:简单易用,快速上手
To sort out messy header files, I use include what you use
图像检索(image retrieval)
新享科技发布小程序UniPro小优 满足客户移动办公场景
regular expression
第十八届IET交直流输电国际会议(ACDC2022)于线上成功举办
Solution of dealer collaboration system in building materials industry: empowering enterprises to build core competitiveness
Blood spitting finishing nanny level series tutorial - play Fiddler bag grabbing tutorial (2) - first meet fiddler, let you have a rational understanding
To sort out messy header files, I use include what you use
设置窗体透明 隐藏任务栏 与全屏显示
PingCode 性能测试之负载测试实践
Is it safe for Great Wall Securities to open an account? How to open a securities account
一加10 Pro和iPhone 13怎么选?
Two methods of MD5 encryption
Superscalar processor design yaoyongbin Chapter 6 instruction decoding excerpt
Pytorch深度学习之环境搭建