gpt4 book ai didi

Django URL - 渲染时捕获 NoReverseMatch

转载 作者:行者123 更新时间:2023-12-01 14:45:59 24 4
gpt4 key购买 nike

我在尝试使用 url 标记链接到 View 时遇到了这个错误。错误发生在这一行:

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

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 %}

最佳答案

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

关于Django URL - 渲染时捕获 NoReverseMatch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7092710/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com