2016-08-17 6 views
3

で私はDjango tutorial part 3を追っていると私はhttp://localhost:8000/polls/を表示しようとすると、次のエラーを取得しています:Djangoのチュートリアルパート3 - NoReverseMatch /ポーリング/

**Reverse for 'detail' with arguments '('',)' and keyword arguments '{}' not found. 1 pattern(s) tried: [u'polls/(?P<question_id>[0-9]+)/$']** 

次のように私のファイルは、次のとおりです。

個人用サイト/urls.py:

from django.conf.urls import include, url 
from django.contrib import admin 
urlpatterns = [ 
    url(r'^polls/', include('polls.urls', namespace="polls")), 
    url(r'^admin/', admin.site.urls), 
] 

世論調査/ urls.py:

from django.conf.urls import url 
from . import views 
app_name = 'polls' 
urlpatterns = [ 
    url(r'^$', views.index, name='index'), 
    url(r'^(?P<question_id>[0-9]+)/$', views.detail, name='detail'), 
    url(r'^(?P<question_id>[0-9]+)/results/$', views.results, name='results'), 
    url(r'^(?P<question_id>[0-9]+)/vote/$', views.vote, name='vote'), 
] 

世論調査/ detail.html:

<h1>{{ question.question_text }}</h1> 
<ul> 
{% for choice in question.choice_set.all %} 
    <li>{{ choice.choice_text }}</li> 
{% endfor %} 
</ul> 

世論調査/テンプレート/世論調査/ index.htmlを:

<li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li> 

このエラーは何を意味するのでしょうか?

どうすればデバッグできますか?

修正を提案できますか?

N.b.私が見て、同様の質問への回答を試してみました:

NoReverseMatch at /polls/ (django tutorial) Django 1.8.2 -- Tutorial Chapter 3 -- Error: NoReverseMatch at /polls/ -- Python 3.4.3 NoReverseMatch - Django 1.7 Beginners tutorial Django: Reverse for 'detail' with arguments '('',)' and keyword arguments '{}' not found https://groups.google.com/forum/#!msg/django-users/etSR78dgKBo/euSYcSyMCgAJ NoReverseMatch at /polls/ (django tutorial) https://www.reddit.com/r/django/comments/3d43gb/noreversematch_at_polls1results_in_django/

編集は、私は当初、次の質問を逃しました。その優れた答えは部分的に私の質問(デバッグ方法)に答えるが、私の特定の問題をカバーしていない。

What is a NoReverseMatch error, and how do I fix it?

+0

[NoReverseMatchエラーとは何ですか?また修正するにはどうすればいいですか?](http://stackoverflow.com/questions/38390177/what-is-a-noreversematch-error-and-how-do- i-fix-it) – Sayse

+0

この特定のケースの実際の問題は、 'question.id'が空であることです。 – Sayse

+0

@Sayseありがとう、エラーが予想され、私はhttp://を見ているとは思わないlocalhost:8000/polls /? – atomh33ls

答えて

1

これが問題だった:

世論調査/テンプレート/ポーリング/ index.htmlにはされている必要があります。

{% if latest_question_list %} 
    <ul> 
    {% for question in latest_question_list %} 
     <li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li> 
    {% endfor %} 
    </ul> 
{% else %} 
    <p>No polls are available.</p> 
{% endif %} 

私はうっかり次の行で、ファイル全体を交換していました、関連する行を更新するだけではなく(暗黙的にhere

<li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li> 

コメントに@Sayseで述べたように、これはquestion.idが空でエラーが発生したことを意味します。