Modify the URL,

Source: Internet
Author: User

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,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.