嗨,我正在开发一个学生数据库应用程序,我制作了更多功能并偶然发现了这个错误。一切似乎都很清楚 我明白这个错误是什么意思,因为我之前遇到过这个应用程序。我不知道出了什么问题。
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>
我的views.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 %}
我的student.html
{% if students %}
<ul>
{% for student in students %}
<li>{{student.First_name}}</li>
{% endfor %}
</ul>
我的URLconf
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'),
)
答案 0 :(得分:2)
您的主要学校网址 $ ,这就是您收到错误的原因
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^school/',include('school.urls',namespace='school')),
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += staticfiles_urlpatterns()
随着我的进一步发展,这些是我遇到的错误: