2012-07-31 2 views
0

장고 자습서를 수행 중이며 튜토리얼 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을 정확하게 분리하려면 어떻게해야합니까?

답변

4

이것은 버전 문제입니다. 당신은 어떻게해서 Django의 개발 버전에 대한 링크를 찾았고, 1.4 버전을 사용하고 있습니다. 이 릴리스 이후 변경된 사항 중 하나는 따옴표가 필요하지 않은 템플릿의 URL 이름이 있지만 지금은 URL 이름이 변경된다는 것입니다. 그래서 오류 메시지의 두 세트의 따옴표 안에 URL 이름이 들어 있습니다.

보유하고있는 장고 버전과 일치 시키려면 this version of the tutorial을 사용해야합니다. (개발 버전을 설치할 수도 있지만 권장하지 않습니다.)

+0

고맙습니다. 나는 URL에서 'dev'를 발견하지 못했다. – Andy

관련 문제