Conteúdo do Curso
Django: First Dive
Django: First Dive
Links to Views
The DTL allows us to create links to Views directly. What is meant by this? The URL addresses to Views can be changed while the development process. DTL finds the using URL automatically through the URL pattern name.
Look at the implemented URL pattern inside the urls.py
file:
The DTL has tools that insert links from the URL pattern through the pattern name into the HTML page. Such operations are performed using the following syntax:
For example, the link to the post list:
Note
The quotes inside the
url
function and thehref
parameter should be different.
Result
Now we have this link in the main page in the browser:
The HTML document structure in browser:
The link opens the http://127.0.0.1:8000/posts/
URL address in your browser.
Thus, you can create links to any endpoint of your application, and changing the URL address will not affect the pages, which protects you from additional changes in the HTML pages.
Obrigado pelo seu feedback!