当前位置:网站首页>flask之蓝图 补充openpyxl
flask之蓝图 补充openpyxl
2022-07-28 20:46:00 【5xp_2001】
由于我们现在的项目开发是一个相对于来说非常耗时间和精力的一个工程,如果我们将所有的Flask的请求方法都写在同一个文件下的话,非常的不便于我们的代码的管理和后期的功能代码的添加
如下示例:我们在一个文件中写入多个路由,这会使代码维护变得困难。

如图所示,如果我们将所有的请求方法写在同一个处理文件下面的话,会导致我们的代码显得很没有逻辑性,如果我们后期想要修改代码或者添加新的代码的话,就会显得很尴尬,不知道如何的下手,此时就需要我们的所谓的蓝图来解决这个问题了,如果学过django的程序员可能了解过django中的app的作用了,没错,django中的app的主要作用就是将django的项目分成一个个单独的app,然后将所有的app分配不同的处理功能,通过路由分配将它们连接成一个大的django项目,其实Flask中的蓝图和django中的app功能大同小异,下面我们大概的了解一下Flask的蓝图,代码如下
我们首先创建一个主的路由配置文件manage.py,该文件主要的作用就是启动整个的Flask框架(项目),如图所示

接着,我们在manage.py的平级的目录下创建两个文件admin.py user.py,我们大概的看一下两个文件中的内容


这两个文件相当于django中的两个app了,不同是django中的路由分配是将大的路由通过include分配给app的urls.py,而Flask是通过蓝图注册的方式将蓝图添加到主app中,user.py,admin.py中的主要是创建蓝图,然后为创建的蓝图可以添加部分的路由配置,接着我们就可以在主路由文件manage.py中将我们创建的蓝图注册到主app中了。

这样我们配置好了以后就可以实现我们的路由分层管理了,我们来试一下,运行主程序manage.py

我们在浏览器中访问我们所设置的路由


我们我请求的路由和我们所设置的返回值是一样的,这样我们就大概的完成了一个Flask的蓝图的注册,实现了文件功能的分层次管理了。
补充

边栏推荐
- Learn kotlin - extension function
- Is mov format a still image file format
- [CS231N]Lecture_ 2:Image Classification pipelin
- vuejs中如何实现动态路由切换及路由的缓存
- Add DNS server to LAN for domain name resolution
- Lin Xiaobin, head of Tencent cloud database, borrowed 100 million yuan to speculate in stocks? Insider: the amount is not true
- Part 8: creating camera classes
- Leetcode integer exercises integer inversion
- TensorFlow Serving 高性能的机器学习模型服务系统
- Clearing of applet component timer
猜你喜欢
随机推荐
Win11 how to open software notification
Typeof principle
Lin Xiaobin, head of Tencent cloud database, borrowed 100 million yuan to speculate in stocks? Insider: the amount is not true
Learn kotlin - extension function
Hcip experiment (12)
Mysql内置函数
vuejs中如何实现动态路由切换及路由的缓存
lotus 1.16.0 延长扇区过期时间
Summary of the use of hash table set and map when leetcode brushes questions
Hcip experiment (15)
SQL injection less42 (post stack injection)
Why is 0.1 + 0.2 not equal to 0.3? How to solve this problem?
CDN working principle
2021数学建模B组练习
Desai wisdom number - line chart (stacking area chart): ranking of deposits of different occupational groups in the proportion of monthly income in 2022
Remember the first line segment tree (corresponding to Luogu 3372)
Static details of static members
Ecmasript 5/6 notes
Sword finger offer II 064. magic Dictionary (medium dictionary tree string design)
mysql create语句能不能用来建立表结构并追加新的记录






![[CS231N]Lecture_2:Image Classification pipelin](/img/4f/de56b071560ada746c587a9dbc5f02.jpg)

