python_django_template_url reverse lookup

What is the url reverse lookup?

  Generally, we diango internal URLs in order to match: URL → url → views → templates → <a href="suck/good/"> </a> (address template) → url → .......

General configuration url here it is hard to write the link address, url reverse lookup is generated according to the reverse of our url configuration URL (or we call reasoning) a template in the url address

 

Why url reverse lookup?

  Links We use in the view / template is generally hard links (that is hard-coded fixed links, such as: suck / good /) after modifying the url configuration link all our hard links in html template requires us to manually is to modify, if we use the url reverse analysis , we modified the configuration url links, we will not have to manually modify the link html template, because we url reverse lookup dynamically generated links will address what we need .

 

django url parameter corresponding to the reverse analysis of:

Note: In our django2.x we need to add at the application level: app_name = 'inn' this code.

       url (r'good / (\ d +) / $ ', views.good, name =' good ') # / (/ d +) / parameters for matching, the corresponding parameters may also operate in the views.good.

 

Guess you like

Origin www.cnblogs.com/Vera-y/p/11936683.html