当前路径photos /与以下任何都不匹配

时间:2019-06-04 16:27:42

标签: django

我试图在django中运行一个应用程序,但遇到此错误:即使我不确定代码的哪一部分有问题,当前路径photos /与任何这些都不匹配。这是我的代码:

views.py:

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

def index(request):
  return HttpResponse("<h>This is the main page</h>")

urls.py:

from django.contrib import admin
from django.urls import path
from photoapp import views

urlpatterns = [
path('', views.index, name='index'),
]

主要urls.py:

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

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

设置:

DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'photoapp.apps.PhotoappConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

 MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'photop.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'photop.wsgi.application'

我也尝试在照片后使用斜杠,但问题仍然存在。

0 个答案:

没有答案