如何获得Django Flatpages模板的反向网址 [英] How can I get the reverse url for a Django Flatpages template

查看:117
本文介绍了如何获得Django Flatpages模板的反向网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取Django Flatpages模板的反向网址

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

推荐答案

在root urlconf中包含平板页面:

Include flatpages in your root urlconf:

from django.conf.urls.defaults import *

urlpatterns = patterns('',
    ('^pages/', include('django.contrib.flatpages.urls')),
)

然后,在你看来,你可以这样调用:

Then, in your view you can call reverse like so:

from django.core.urlresolvers import reverse

reverse('django.contrib.flatpages.views.flatpage', kwargs={'url': '/about-us/'})
# Gives: /pages/about-us/

在模板中,使用{%url%}标签(内部调用反向): p>

In templates, use the {% url %} tag (which calls reverse internally):

<a href='{% url django.contrib.flatpages.views.flatpage url="/about-us/" %}'>About Us</a>

这篇关于如何获得Django Flatpages模板的反向网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆