在尝试使用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/算法/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 %}