一、URL路由分发
1.创建一个新的app03 - python manage.py starapp app03
2.在app02和app03里面创建urls文件,填写各自的url
3.在总的url导入inclue
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path(‘admin/‘, admin.site.urls),
path(‘app02/‘,include(‘app02.urls‘)),
path(‘app03/‘,include(‘app03.urls‘))
]
二、 url正则表达式及去掉get请求的参数带“?”
1.前端编辑哪里取id是去掉 “?nid=”
<ul>
{% for i in user_list %}
<li>{{ i }}|<a href="/edit/{{ i }}">编辑</a></li>
{% endfor %}
</ul>
2.在url里面设置正则
re_path(‘edit/(\w+)‘, views.edit),
3.在views里面函数里面传入参数“a1” 接受正则的参数设定
def edit(request,a1):
print(a1)
return HttpResponse(‘hhh‘)
三、
1.终止符:
^edit$
2.伪静态
url(r‘^edit/(\w+).html$‘, views.edit),
原文:https://www.cnblogs.com/jmc218/p/13810356.html