我收到此错误。找不到页面(404)请求方法:GET请求URL:http://127.0.0.1:8000/polls/

时间:2020-10-14 06:40:41

标签: python

我的民意调查app / views.py

from django.http import Http404   
from django.shortcuts import render    
from django.http import HttpResponse

def index(request):   
    return HttpResponse("hello this is venkat from lakshmipuram.")

def detail(request, question_id):
    return HttpResponse("You're looking at question %s." % question_id)

def results(request, question_id):    
    response = "You're looking at the results of question %s."
    return HttpResponse(response % question_id)

def vote(request, question_id):    
    return HttpResponse("You're voting on question %s." % question_id)

我的民意调查app / urls.py

from django.urls import path    
from . import views

urlpatterns = [
    # ex: /polls/    
    path('', views.index, name='index'),

    # ex: /polls/5/    
    path('<int:question_id>/', views.detail, name='detail'),

    # ex: /polls/5/results/    
    path('<int:question_id>/results/', views.results, name='results'),

    # ex: /polls/5/vote/    
    path('<int:question_id>/vote/', views.vote, name='vote'),
]

我的项目/urls.py

from django.contrib import admin    
from django.urls import include, path

urlpatterns = [    
    path('', include('polls.urls')),    
    path('admin/', admin.site.urls),
]

1 个答案:

答案 0 :(得分:0)

更改您的项目/urls.py

from django.contrib import admin    
from django.urls import include, path

urlpatterns = [    
    path('polls/', include('polls.urls')),    
    path('admin/', admin.site.urls),
]