嗨,我正在开发一个学生数据库应用程序,我制作了更多功能并偶然发现了这个错误。一切似乎都很清楚我理解这个错误的含义,因为我以前遇到过这个应用程序。我不知道出了什么问题。
TemplateSyntaxError at /school/
Caught NoReverseMatch while rendering: Reverse for 'cat' with arguments '('',)' and keyword arguments '{}' not found.
Exception Type: TemplateSyntaxError
Exception Value: Caught NoReverseMatch while rendering: Reverse for 'cat' with arguments '('',)' and keyword arguments '{}' not found.
In template /home/tafe/mysite/school/templates/index.html, error at line 3
Caught NoReverseMatch while rendering: Reverse for 'cat' with arguments '('',)' and keyword arguments '{}' not found.
1 {% if students %}
2 <ul>
3 {% for student in students %}
4 <li><a href="{% url school:cat poll.id %}">{{student.First_name}}</li>
我的观点.py
from mysite.school.models import student
from django.shortcuts import render_to_response
from django.http import HttpResponse,Http404
def index(request):
students = student.objects.all()
return render_to_response('index.html',{'students':students})
def cat(request,poll_id):
students = get_object_or_404(student,pk =poll_id)
return render_to_response('student.html',{'students':student})
我的 index.html
{% if students %}
<ul>
{% for student in students %}
<li><a href="{% url myapp:cat poll.id %}">{{student.First_name}}</li>
{% endfor %}
</ul>
{% endif %}
我的学生.html
{% if students %}
<ul>
{% for student in students %}
<li>{{student.First_name}}</li>
{% endfor %}
</ul>
我的网址配置
from django.conf.urls.defaults import patterns,include , url
from django.contrib import admin
from mysite.school.views import index,cat
admin.autodiscover()
urlpatterns = patterns ('',
url(r'^$',index),
url(r'^(?P<poll_id>\d+)/$',cat,name='cat'),
)