当前位置:网站首页>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>
边栏推荐
- Is BigDecimal safe to calculate the amount? Look at these five pits~~
- Load test practice of pingcode performance test
- Developers, MySQL column finish, help you easily from installation to entry
- 公司要上监控,Zabbix 和 Prometheus 怎么选?这么选准没错!
- 一文掌握数仓中auto analyze的使用
- Leetcode list summary
- 【HCIA持续更新】广域网技术
- 长城证券安全不 证券开户
- R language plot visualization: plot visualizes overlapping histograms and uses geom at the top edge of the histogram_ The rug function adds marginal rug plots
- 居家打工年入800多万,一共五份全职工作,他还有时间打游戏
猜你喜欢
Blood spitting finishing nanny level series tutorial - play Fiddler bag grabbing tutorial (2) - first meet fiddler, let you have a rational understanding
RecastNavigation 之 Recast
解读数据安全治理能力评估框架2.0,第四批DSG评估征集中
OPPO小布推出预训练大模型OBERT,晋升KgCLUE榜首
leetcode:421. The maximum XOR value of two numbers in the array
如何进行MDM的产品测试
Talk about seven ways to realize asynchronous programming
整理混乱的头文件,我用include what you use
To sort out messy header files, I use include what you use
开发者,MySQL专栏完更,助你轻松从安装到入门进阶
随机推荐
使用3DMAX制作一枚手雷
Developers, MySQL column finish, help you easily from installation to entry
长城证券开户安全吗 证券账户怎么开通
整理混乱的头文件,我用include what you use
智捷云——元宇宙综合解决方案服务商
CANN算子:利用迭代器高效实现Tensor数据切割分块处理
About the pit of firewall opening 8848 when Nacos is started
金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
码农版隐秘的角落:作为开发者最讨厌的5件
Perfectly integrated into win11 style, Microsoft's new onedrive client is the first to see
RecastNavigation 之 Recast
Firewall basic transparent mode deployment and dual machine hot standby
Win32 API 访问路由的加密网页
国产数据库TiDB初体验:简单易用,快速上手
Blood spitting finishing nanny level series tutorial - play Fiddler bag grabbing tutorial (2) - first meet fiddler, let you have a rational understanding
KS007基于JSP实现人个人博客系统
Cocoscreator event dispatch use
Great Wall Securities security does not open a securities account
With an annual income of more than 8 million, he has five full-time jobs. He still has time to play games
【Hot100】31. 下一个排列