modify the url,

The first scenario:

   No matter how the url changes, the url in the form is always 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: (applicable to staying on the current page after the current page is 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 based on this name in the future *****

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'), #reverse


generated url
def func(request, *args, **kwargs):
from django.urls import reverse

url1 = reverse('i1') # asdfasdfasdf/
url2 = reverse('i2', args=(1,2,)) # 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:
# Current URL

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325132094&siteId=291194637
URL
URL
URL
URL