url模板标签在django模板 [英] url template tag in django template

查看:191
本文介绍了url模板标签在django模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用django中的url模板标记,但没有幸运,

I was trying to use the url template tag in django, but no lucky,

我定义了我的urls.py这样的

I defined my urls.py like this

urlpatterns = patterns('',
    url(r'^analyse/$',              views.home,  name="home"),
    url(r'^analyse/index.html',     views.index, name="index"),
    url(r'^analyse/setup.html',     views.setup, name="setup"),
    url(r'^analyse/show.html',      views.show,  name="show"),
    url(r'^analyse/generate.html',  views.generate, name="generate"),

我在我的视图中定义了这样的URL格式

I defined the url pattern in my view like this

{% url 'show'%}

然后我收到这个错误消息

then I got this error message


在呈现时捕获异常:
反向''show' '与参数
'()'和关键字参数'{}'不是
发现。

Caught an exception while rendering: Reverse for ''show'' with arguments '()' and keyword arguments '{}' not found.

原始追溯(最近调用
持续):文件
/Library/Python/2.5/site-packages/django/template/debug.py,
line 71,在render_node
result = node.render(context)文件
/Library/Python/2.5/site-packages/django/template/defaulttags.py,
line 155,在render
nodelist.append(node.render(context))
文件
/Library/Python/2.5/site-packages/django/template/defaulttags.py,
line 382,在render
raise e NoReverseMatch:Reverse for''show' '''和
关键字参数'{}'没有找到。

Original Traceback (most recent call last): File "/Library/Python/2.5/site-packages/django/template/debug.py", line 71, in render_node result = node.render(context) File "/Library/Python/2.5/site-packages/django/template/defaulttags.py", line 155, in render nodelist.append(node.render(context)) File "/Library/Python/2.5/site-packages/django/template/defaulttags.py", line 382, in render raise e NoReverseMatch: Reverse for ''show'' with arguments '()' and keyword arguments '{}' not found.

我想知道为什么django失败渲染?在tempalte中定义它的正确方法是什么?

I am wondering why django failed to render? what is the right way to define it in the tempalte?

推荐答案

重要提示:这是针对django 1.4。在django 1.5它恰恰相反。

IMPORTANT: this was for django 1.4. At django 1.5 it is just the opposite.

尝试使用没有引号的url名称

try using url names without quotes

{% url show %}

不是这个

{% url 'show'%}

这篇关于url模板标签在django模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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