Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
661 views
in Technique[技术] by (71.8m points)

url template tag in django template

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

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"),

I defined the url pattern in my view like this

{% url 'show'%}

then I got this error message

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

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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

try using url names without quotes

{% url show %}

not this

{% url 'show'%}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...