Django URL - 渲染时捕获NoReverseMatch

时间:2011-08-17 12:24:06

标签: django django-templates

我在尝试使用url标记链接到视图时遇到此错误。此行发生错误:

{% for algorithim in algorithims %}

在模板中。

不确定我在哪里出错了......我想我已经附上了所有必要的信息,但如果你需要查看其他信息,请告诉我。

错误:

TemplateSyntaxError at /wiki/algorithims/
Caught NoReverseMatch while rendering: Reverse for 'wiki.views.algorithim.view' with arguments '(0,)' and keyword arguments '{}' not found.

url.conf(wiki):

   from django.conf.urls.defaults import *

   urlpatterns = patterns('wiki.views',
       url(r'^$', 'index'),
       url(r'^algorithims/$', 'algorithims.index'),
       url(r'^algorithims/(?P<alg_id>\d+)/$', 'algorithims.view')
    )

wiki.views.algorithim:

@login_required
def index(request): 
    algorithims = Algorithms.objects.all()
    return render_to_response('wiki/algorithims/index.html', 
                          {'algorithims': algorithims 
                           },
                          context_instance=RequestContext(request)) 

templates / wiki / algorithims / index.html:

{% extends "wiki/base.html" %} 

{% block content %}
<div>
    {% if algorithims %}    
        {% for algorithim in algorithims %}
            <a href="{% url wiki.views.algorithim.view algorithim.alg_id %}">{{ algorithim.alg_name }}</a>
        {% endfor %}
    {% else %}
        No algorithims found!
    {% endif %}
</div>
{% endblock %}

2 个答案:

答案 0 :(得分:2)

您的视图在urlconf中被称为algorithms.view,但您在网址标记中将其称为algorithm.view,即没有s

答案 1 :(得分:0)