장고 자습서를 수행 중이며 튜토리얼 3에서 Decoupling the URLConfs으로 만들었습니다.이 단계를 시작하기 전에 모든 것이 작동하고있었습니다.Django 튜토리얼 3에서 URLConf를 올바르게 분리하는 방법은 무엇입니까?
NoReverseMatch at /polls/
Reverse for ''polls.views.detail'' with arguments '(1,)' and keyword arguments '{}' not found.
Request Method: GET
Request URL: http://localhost:8000/polls/
Django Version: 1.4
Exception Type: NoReverseMatch
Exception Value:
Reverse for ''polls.views.detail'' with arguments '(1,)' and keyword arguments '{}' not found.
Exception Location: e:\Django\development\tools\PortablePython\PortablePython2.7.3.1\App\lib\site-packages\django\template\defaulttags.py in render, line 424
Python Executable: e:\Django\development\tools\PortablePython\PortablePython2.7.3.1\App\python.exe
내 views.py
은 다음과 같습니다 : 나는 템플릿에서 하드 코드 된 URL을 제거하는 마지막 단계를 수행 할 때 이제
<li><a href="{% url 'polls.views.detail' poll.id %}">{{ poll.question }}</a></li>
에
<li><a href="/polls/{{ poll.id }}/">{{ poll.question }}</a></li>
을 변경하는 나는이 오류가 발생합니다 :
from django.shortcuts import render_to_response, get_object_or_404
from polls.models import Poll
def index(request):
latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
return render_to_response('polls/index.html', {'latest_poll_list': latest_poll_list})
def detail(request, poll_id):
p = get_object_or_404(Poll, pk=poll_id)
return render_to_response('polls/detail.html', {'poll': p})
def results(request, poll_id):
return HttpResponse("You're looking at the results of poll %s." % poll_id)
def vote(request, poll_id):
return HttpResponse("You're voting on poll %s." % poll_id)
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^polls/', include('polls.urls')),
url(r'^admin/', include(admin.site.urls)),
)
그리고 polls/urls.py
는 다음과 같습니다 : 14,내 프로젝트 urls.py
은 다음과 같습니다
from django.conf.urls import patterns, include, url
urlpatterns = patterns('polls.views',
url(r'^$', 'index'),
url(r'^(?P<poll_id>\d+)/$', 'detail'),
url(r'^(?P<poll_id>\d+)/results/$', 'results'),
url(r'^(?P<poll_id>\d+)/vote/$', 'vote'),
)
는 분명 내가 뭔가를 놓친,하지만 난 지금의 3 몇 번에 걸쳐 왔고 알아낼 수 없습니다 내가 놓친 것. 이 URL을 정확하게 분리하려면 어떻게해야합니까?
고맙습니다. 나는 URL에서 'dev'를 발견하지 못했다. – Andy