How can I get the reverse url for a Django Flatpages template

后端 未结 10 1178
情深已故
情深已故 2021-01-31 10:33

How can I get the reverse url for a Django Flatpages template

10条回答
  •  遇见更好的自我
    2021-01-31 10:50

    You need to redeclare the url conf and cannot rely on the official 'django.contrib.flatpages.urls' that the doc is encouraging us to use.

    This won't be more difficult, just include in your urls.py

    from django.conf.urls import patterns, url
    
    urlpatterns += patterns('',
        ...
        url(r'^pages(?P.*)$', 'django.contrib.flatpages.views.flatpage', name='flatpage'),
        ...
    )
    

    And now you can use your usual reverse url template tag

    About Us
    

    Or to display a list of all flat pages

      {% get_flatpages as flatpages %} {% for page in flatpages %}
    • {{ page.title }}
    • {% endfor %}

提交回复
热议问题