2013-02-26 5 views
0

안녕하세요 저는 학생용 데이터베이스 앱에서 작업 중이며 더 많은 기능을 만들었으며이 오류에 걸려 넘어졌습니다. 모든 것이 분명해 보입니다. 이 앱이 이전에 발생했기 때문에이 오류의 의미를 이해했습니다. 나는 무엇이 잘못되었는지 모른다.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'), 
) 
+0

내가 부 풀릴 수 있는지 알아 보려면 앱을 쓰러 뜨리십시오. 바쁘지 않으면 – donkeyboy72

+0

괜찮습니다. 보내 셨습니다. 감사합니다 cathy – donkeyboy72

+0

...... – catherine

답변

2

주 urlconf가 $을 가지고,이 오류를 얻을 이유입니다

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() 

내가 더 나아가, 이러한 내가 발생한 오류입니다 :

  1. 은 색인이없는 http 응답이 있습니다.
  2. 정의하지 않았습니다. get_object_404
  3. 학생이 학생 인 경우 동일한 변수를 사용하지 마십시오. 학생과 함께, 학생 또는 무엇이든 만들 수 있습니다.
  4. get_object_404를 사용하거나 하나의 값만 렌더링 할 경우. forloop을 사용하면 안됩니다. 그냥 student.first_name 또는 student.id로 전화하십시오.
+0

다른 오류에 대해 유감 오. 그것은 한 번에 한 줄씩 내 USB 폴더에 복사 할 때 발생했습니다. 나는 그 줄들을 잊어 버렸을 것입니다. – donkeyboy72

+0

. 내 고양이 기능을 아십니까? 내 안에 forloop 함께 get_object_404 사용하고 그것을 너무 그것을 student.objects.all() 및 작동하지 않았다 작동하지 않았다 : D – donkeyboy72

+0

당신은 하나의 데이터를 호출하기 때문에 그것은 forloop에서 작동하지 않습니다. Forloop은 필터링 할 데이터가 많은 경우에만 작동합니다. – catherine

관련 문제