Django Learning Notes (iii)--django hyperlinks

Source: Internet
Author: User
Tags root directory

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%}

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.