当前位置:网站首页>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>
边栏推荐
- Ble HCI flow control mechanism
- TP configuring multiple databases
- The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!
- Solution of dealer collaboration system in building materials industry: empowering enterprises to build core competitiveness
- 无心剑中译伊丽莎白·毕肖普《一门技艺》
- 电子宠物小狗-内部结构是什么?
- 公司要上监控,Zabbix 和 Prometheus 怎么选?这么选准没错!
- 内核中时间相关的知识介绍
- Is BigDecimal safe to calculate the amount? Look at these five pits~~
- Zebras are recognized as dogs, and the reason for AI's mistakes is found by Stanford
猜你喜欢
聊聊异步编程的 7 种实现方式
Load test practice of pingcode performance test
ble HCI 流控机制
【HCIA持续更新】WLAN工作流程概述
就在今天丨汇丰4位专家齐聚,共讨银行核心系统改造、迁移、重构难题
Internet addiction changes brain structure: language function is affected, making people unable to speak neatly
The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!
What is low code development?
kaili不能输入中文怎么办???
超标量处理器设计 姚永斌 第6章 指令解码 摘录
随机推荐
tx.origin安全问题总结
长城证券开户安全吗 证券账户怎么开通
Rainfall warning broadcast automatic data platform bwii broadcast warning monitor
一加10 Pro和iPhone 13怎么选?
大规模服务异常日志检索
【Hot100】32. 最长有效括号
【HCIA持续更新】WLAN工作流程概述
Datakit -- the real unified observability agent
超标量处理器设计 姚永斌 第7章 寄存器重命名 摘录
【测试开发】软件测试——基础篇
Vb无法访问数据库stocks
[HCIA continuous update] overview of WLAN workflow
Mathematical analysis_ Notes_ Chapter 7: differential calculus of multivariate functions
Ks007 realizes personal blog system based on JSP
R language plot visualization: plot visualization of multiple variable violin plot in R with plot
正则表达式
NFT liquidity market security issues occur frequently - Analysis of the black incident of NFT trading platform quixotic
New technology releases a small program UNIPRO to meet customers' mobile office scenarios
Dynamic programming stock problem comparison
要上市的威马,依然给不了百度信心