Polls tutorial for Django을 통해 작업하고 있습니다. 나는 여섯 번째 부분의 시작까지 그것을 만들었다.설문 조사 응용 - django 튜토리얼이 작동하지 않습니다.
어떤 이유에서든 내 클래스 기반 제네릭 뷰는 모두 EXCEPT 클래스 기반 인덱스 뷰에서 작동합니다. 로컬 호스트를로드하려고 할 때 : 8000/I는 다음과 같은 오류 얻을 : 여기
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
^polls/
^admin/
The current URL, , didn't match any of these.
내 내 사이트/urls.py입니다 :
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^polls/', include('polls.urls')),
url(r'^admin/', admin.site.urls),
]
그리고 여기 내 여론 조사/urls.py
from django.conf.urls import url
from . import views
app_name = 'polls'
urlpatterns = [
url(r'^$', views.IndexView.as_view(), name='index'),
url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='detail'),
url(r'^(?P<pk>[0-9]+)/results/$', views.ResultsView.as_view(), name='results'),
url(r'^(?P<question_id>[0-9]+)/vote/$', views.vote, name='vote'),
]
다음은 polls/views.py입니다. 나는 단지 IndexView 부분을 붙이고있다. 나머지 클래스 기반 조회수는 현재 작동 중입니다.
from django.shortcuts import get_object_or_404, render
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.views import generic
from django.utils import timezone
from .models import Choice, Question
# Create your views here.
class IndexView(generic.ListView):
template_name = 'polls/index.html'
context_object_name = 'latest_question_list'
def get_queryset(self):
# Return last five published questions (not inc. future)
return Question.objects.filter(
pub_date__lte=timezone.now()
).order_by('-pub_date')[:5]
누락 된 항목이 있습니까? 어떤 도움이라도 대단히 감사하겠습니다.
감사합니다! 여분의 보너스로 답은 저에게 '인덱스'에 대해 생각하는 법을 가르쳐 줬습니다. 매우 감사. – Dan