Django错误{找不到页面,错误404},

时间:2020-09-20 08:35:01

标签: python django

[目录1] error 在尝试连接时出现此错误

Using the URLconf defined in project.urls, Django tried 
these URL patterns, in this order:

admin/
 The current path, polls/, didn't match any of these.

C:\ Users \ Kwaku Biney \ Desktop \ dj \ mysite \ polls \ urls.py

 from django.urls import path
  from . import views
urlpatterns = [
path('', views.index, name='index'),]

C:\ Users \ Kwaku Biney \ Desktop \ dj \ mysite \ mysite \ urls.py

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

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

mysite \ polls \ views.py

 from django.shortcuts import render
 from django.http import HttpResponse
 def index(request):
return HttpResponse("Hello, world. You're at the polls index.")

settings.py

 # Application definition

 # Application definition

  INSTALLED APPS= [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls',]

polls / apps.py

from django.apps import AppConfig
class PollsConfig(AppConfig):
   name = 'polls'

2 个答案:

答案 0 :(得分:0)

mysqite / mysite / urls.py

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

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

mysite / polls / urls.py

from django.urls import path,include
from . import views
urlpatterns = [
    path('', views.index),
]

mysite / polls / views.py

from django.shortcuts import render

from django.http import HttpResponse
def index(request):
    return HttpResponse("Hello, world. You're at the polls index.")

运行服务器后enter image description here

答案 1 :(得分:0)

问题是我没有保存文件。在Windows的VSCode中是通过CTRL + K + S做到的。 page

您也可以通过File =>在菜单栏上自动保存,在VsCode上启用自动保存。