First scenario:
No matter how the URL changes, the URL in the form will always be the same
http://127.0.0.1:8000/CC/indexssssssssssssssssss/
URL (r ' ^indexssssssssssssssssss/', views.index,name= ' Indexx '),
<form action= "{% url ' indexx '%}" method= "POST" >#}
def index (Request):
Return render (request, "index1.html", {' user_dict ': user_dict}
Second scenario:
URL Plus ID
http://127.0.0.1:8000/CC/indexssssssssssssssssss/3/
URL (r ' ^indexssssssssssssssssss/(\d+)/', views.index,name= ' Indexx '),
<form action= "{% url ' Indexx ' 3%}" method= "POST" >
def index (Request,nid):
Print Nid
Return render (request, "index1.html", {' user_dict ': user_dict})
The third scenario shows the current URL: (for continuing on the current page after the current one has been submitted)
http://127.0.0.1:8000/CC/indexssssssssssssssssss/33/
URL (r ' ^indexssssssssssssssssss/(\d+)/', views.index,name= ' Indexx '),
<form action= "{{request.path_info}}" method= "POST" >#}
def index (Request,nid):
Print Request.path_info
Return render (request, "index1.html", {' user_dict ': user_dict,})
Name the URL-routing relationship, * * * * * You can generate the URL you want later * * * * *
URL (r ' ^asdfasdfasdf/', Views.index, name= ' I1 '),
URL (r ' ^yug/(\d+)/(\d+)/', Views.index, name= ' i2 '),
URL (r ' ^buy/(? p<pid>\d+)/(? p<nid>\d+)/', Views.index, name= ' i3 '),
#反转生成url
def func (Request, *args, **kwargs):
From Django.urls Import Reverse
URL1 = reverse (' I1 ') # asdfasdfasdf/
URL2 = reverse (' I2 ', args= ()) # yug/1/2/
Url3 = reverse (' i3 ', kwargs={' pid ': 1, "Nid": 9}) # buy/1/9/
Xxx.html
{% url "i1"%} # asdfasdfasdf/
{% url "i2" 1 2} # yug/1/2/
{% url "i3" pid=1 nid=9%} # buy/1/9/
Note:
# The current URL
Modify the URL,