【问题标题】:Django URL - Caught NoReverseMatch while renderingDjango URL - 渲染时捕获 NoReverseMatch
【发布时间】:2011-08-17 12:24:06
【问题描述】:

我在尝试使用 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(维基):

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

模板/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 %}

【问题讨论】:

  • fyp,这是“算法”,而不是“算法”

标签: django django-templates


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    【讨论】:

      猜你喜欢
      • 2012-10-14
      • 2014-10-14
      • 2011-07-06
      • 1970-01-01
      • 2011-04-23
      • 2013-12-27
      • 1970-01-01
      • 1970-01-01
      • 2020-02-10
      相关资源
      最近更新 更多