A. Regular URL (solves the problem that the regular part cannot be matched)
-------xxx.html<a href="/teacher_edit-{{Item.id}}"> Edit </a>-------Url.pypath ('teacher_edit-(\d+)', Views.teacher_edit),--------views.pydefTeacher_edit (req): xxxx########################## #以上的正则url不能被识别, the workaround is as follows:----------------urls.py fromDjango.urlsImportPath,re_path#Introducing the Re_path moduleRe_path ('teacher_edit-(\d+)', Views.teacher_edit),#here is a regular part (\d+), so there is a parameter passed to Teacher_edit ()-----------------views.pydefTeacher_edit (Req,edit):#parameter edit is a regular part of urls.py Print(edit)
Two. Template URL
----------index.html<a href="{% URL"A"B C%}">ABC</a>#Locate the path () of Name= "a" in urls.py, and the URL in path () is not related to a----------Urls.pypath ("(\w+)/(\w+)", views.index,name="A")#only match a here-----------views.pydefIndex (REQ,B,C): #B, the C parameter is the regular part of the URL in path ()returnRender (req,"index.html")
Django (template url+ regular URL)