当前位置:网站首页>Unit 4 Routing Layer
Unit 4 Routing Layer
2022-08-02 14:18:00 【czy1206527605】
Static and dynamic routing
Static Routing
Concept:Static routing is used to map the corresponding view function, where urlpatterns is a global variable in the routing file, which is used to store the mapping relationship between routing and view functionseffect:Routes used for fixed addresses, and routes used in general operations are static routesDynamic Routing
Function:More complex, when the routing settings are changing, dynamic routing is used.path dynamic routing
path('index2//', views.IndexView2.as_view()),class IndexView2(View):def get(self, request, id):return HttpResponse(f"The matched id is {id}") re.path dynamic routing
PS: use regular expressions to write
re_path(r'^(?P\d+)/(?P[a-zA-Z]+)/$',views.IndexView3.as_view())class IndexView3(View):def get(self, request, x, y):return HttpResponse(f"x is {x}, y is {y}") Access the connection: **http://127.0.0.1:8000/abc/123/** to get the x and y values
Route Distribution
Concept: The general route is written directly to the url of the main project.When creating multiple custom applications in the main project, you need to use route distribution include to distribute routes to each application.
Using:
from myapp import urlsurlpatterns = [path('', include(urls))]PS:
You need to create a urls.py file in each application to store the url address in it.
Advantages of routing distribution
1. There are many benefits that route distribution brings us, which allows us to manage each route more conveniently and effectively in multiple app projects
2. It allows our users to see the browsing when visitingThe URL address in the server is more pleasing to the eye
边栏推荐
- 定了!就在7月30日!
- Geoffery Hinton:深度学习的下一个大事件
- 网络安全第二次作业
- The future of financial services will never stop, and the bull market will continue 2021-05-28
- 动手学ocr(一)
- FFmpeg 的AVCodecContext结构体详解
- Supervision strikes again, what about the market outlook?2021-05-22
- redis分布式锁和看门狗的实现
- A number of embassies and consulates abroad have issued reminders about travel to China, personal and property safety
- 保姆级教程:写出自己的移动应用和小程序(篇三)
猜你喜欢

Linux:CentOS 7 安装MySQL5.7

跑yolov5又出啥问题了(1)p,r,map全部为0

logback源码阅读(一)获取ILoggerFactory、Logger

uview 2.x版本 tabbar在uniapp小程序里头点击两次才能选中图标

【ONE·Data || Getting Started with Sorting】

ZABBIX配置邮件报警和微信报警

RHCE第一天作业

IDEA打包jar包

You can't accept 60% slump, there is no eligible for gain of 6000% in 2021-05-27

【Tensorflow】AttributeError: ‘_TfDeviceCaptureOp‘ object has no attribute ‘_set_device_from_string‘
随机推荐
数据机构---第六章图---图的遍历---选择题
ping命令的使用及代码_通过命令查看ping路径
[ROS]ROS常用工具介绍(待续)
uview 2.x版本 tabbar在uniapp小程序里头点击两次才能选中图标
drf视图组件
史上最全!47个“数字化转型”常见术语合集,看完秒懂~
shell脚本“画画”
8583 顺序栈的基本操作
苏州大学:从 PostgreSQL 到 TDengine
redis延时队列
mysql的case when如何用
Sentinel源码(四)(滑动窗口流量统计)
2022-08-02日报:2022年7月最热的10篇AI论文
Flutter 实现光影变换的立体旋转效果
ZABBIX配置邮件报警和微信报警
Haystack的介绍和使用
世界上最大的开源基金会 Apache 是如何运作的?
音频处理:浮点型数据流转PCM文件
第八单元 中间件
Configure zabbix auto-discovery and auto-registration.