嗨我正在學習一個學生數據庫應用程序,我做了更多的功能,並絆倒了這個錯誤。一切似乎都很清楚 我明白這個錯誤是什麼意思,因爲我以前遇到過這個應用程序。我不知道哪裏出了問題。Django TemplateSyntaxError at/school/
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'),
)
它只是弄髒的應用程序,看看有什麼我可以儲存卡.Okay肯定,如果你不忙 – donkeyboy72 2013-02-26 05:31:46
好吧,我把它。謝謝你cathy – donkeyboy72 2013-02-26 05:52:32
送回...... – catherine 2013-02-26 06:36:22