django1.7 use of {%url%} in HTML templates

Source: Internet
Author: User

Cases:

We created a table like this in the template:

You can see that since then there are 2 actions: Modify and delete

In Django we can do this without JavaScript and Ajax,

<a href= "{% url ' list_delete ' i.id%}" > Delete |</a> here the i.id is generated through a tabular loop, specifically the ID primary key for the backend database, which we first Make a variable to see if we click Delete or modify on line 4th, its value is 4<a href= "{% url ' list_modify ' i.id%}" > Modify </a>

We define the path to the 2 URLs in the template and add the IDs of the databases later,

' List_delete '

We're going to be in the urls.py. The URL name that is defined in the

urls.py

URL (r ' ^index/list_modify/(? p<i_id>\d+)/$ ', list_modify,name= ' list_modify '), url (r ' ^index/list_delete/(? p<i_id>\d+)/$ ', list_delete,name= ' list_delete '),

We've defined this so that a URL will be generated later

/INDEX/LIST_MODIFY/4/can look at the above picture, we chose the 4th line, the 4 in the URL is assigned to the I_ID, the specific regular expression can be searched under

At last, I quote this variable in view.py.

def list_modify (request,i_id):


django1.7 use of {%url%} in HTML templates

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.