首页 > 解决方案 > Django错误{页面未找到,错误404},

问题描述

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

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.")

设置.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',]

民意调查/apps.py

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

标签: pythondjango

解决方案


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

您也可以通过 File => Autosave on Menu Bar 打开 VsCode 上的 AutoSave。


推荐阅读