hyperlinks in Django
Destination Address of hyperlink
The href is followed by the destination address
Template can be used {% url ' app_name:url_name ' param%}
App_name: Name of the app namespace
Url_name: Link Name
PARAM: Address Parameters
App_name corresponds to namespace in urls.py in the root directory, url_name corresponds to name in urls.py in the app
re-match URL
Root URLs, written in the second parameter location of the include (), namespace= ' Blogapp ' (the application's namespace)
The third parameter location of the URL () of the app, Name= ' page '
Depends primarily on whether to use Inclue () to refer to another URL configuration file
urls.py under the root directory
Urlpatterns = [
url (R ' ^admin/', admin.site.urls),
url (r ' ^blog/', include (' Blog.urls ', namespace= ' Blogapp ')) ,
]
Blog app's urls.py
Urlpatterns = [
url (R ' ^index/$ ', views.index),
url (r ' ^article/(? p<article_id>[0-9]+)/$ ', views.article_page,name= ' article_page '),
]
Blog app's blog.html
{% for article in articles%}
<a href= "{% url ' blogapp:article_page ' article.id%}" >{{article.title}}</a>
</br>
{% ENDfor%}