Best way of linking to a page in Django

前端 未结 5 2167
臣服心动
臣服心动 2021-02-08 20:02

I managed to create a URL tag for my index. But right now I\'m confused how to add links to other pages.

I put this on my urls.py

url(r\         


        
5条回答
  •  独厮守ぢ
    2021-02-08 20:38

    Just use the same label {% url 'index' %}. You may use each name in urls.py to link to the url.

    urls.py

    url(r'^archive/$', 'mysite.views.archive',name='archive'),
    url(r'^about/$', 'mysite.views.about',name='about'),
    url(r'^contact/$', 'mysite.views.contact',name='contact'),
    

    template

    About
    Contact
    

    If you have many apps, use namespace https://docs.djangoproject.com/en/dev/topics/http/urls/#url-namespaces-and-included-urlconfs

提交回复
热议问题