安装wordpress连接不了数据库文件,如何网页优化,教育机构网站建设公司,网站建设推广合同范本1 django如何处理一个请求
首先Django要使用根URLconf模块#xff0c;通过setting.py配置文件的ROOT_URLCONF来设置。
加载该模块后并查找变量 urlpatterns。这是一个Python的django.conf.urls.url()实例列表。
Django按顺序运行每个URL模式#xff0c;并在匹配所请求的…1 django如何处理一个请求
首先Django要使用根URLconf模块通过setting.py配置文件的ROOT_URLCONF来设置。
加载该模块后并查找变量 urlpatterns。这是一个Python的django.conf.urls.url()实例列表。
Django按顺序运行每个URL模式并在匹配所请求的URL的第一个URL中停止。如下图所示如果请求的URL是http://127.0.0.1:8000/login那么当执行到标记的部分URL时就会结束URL匹配并跳转到后续的地方执行代码
如果没有正则表达式匹配或者在此过程中的任何一点出现异常Django将调用适当的错误处理视图。
2 配置子URL路由表
在任何时候您urlpatterns都可以“包含”其他URLconf模块。使用include关键字包含app中的子路由
from django.urls import include, path
urlpatterns [# ... snip ...path(community/, include(django_website.aggregator.urls)),path(contact/, include(django_website.contact.urls)),# ... snip ...
]请注意此示例中的正则表达式没有$字符串尾匹配字符但包含尾部斜线。 path(community/, include(django_website.aggregator.urls)),如上面的代码所示当URL是http://127.0.0.1:8000/community/...时只要是community/…的URL都会去django_website这个app下面的aggregator子app的urls.py中的urlpatterns去匹配路由django_website.aggregator.urls中的path是去掉之前匹配前缀的。 如请求的URL是http://127.0.0.1:8000/community/test/1当主URL路由表的内容是 path(community/, include(django_website.aggregator.urls)),时django_website.aggregator.urls的path内容是 path(test/1, xxxx, namexxxxx)