简体   繁体   English

Django TemplateDoesNotExist错误

[英]Django TemplateDoesNotExist error

After i uploaded my django project from my local machine to a remote server this error appears 从本地计算机上将django项目上传到远程服务器后,出现此错误

TemplateDoesNotExist at /

registration/login.html

Request Method: GET Request URL: http://ip:8000/ Django Version: 1.8.6 Exception Type: TemplateDoesNotExist Exception Value:

registration/login.html

Exception Location: /home/market/local/lib/python2.7/site-packages/django/template/loader.py in get_template, line 46 Python Executable: /home/market/bin/python Python Version: 2.7.12 Python Path:

['/home/market/src', '/home/market/lib/python2.7', '/home/market/lib/python2.7/plat-x86_64-linux-gnu', '/home/market/lib/python2.7/lib-tk', '/home/market/lib/python2.7/lib-old', '/home/market/lib/python2.7/lib-dynload', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/home/market/local/lib/python2.7/site-packages', '/home/market/lib/python2.7/site-packages']

Server time: Sun, 2 Jul 2017 08:35:49 +0000

and this error appears in django server console 并且此错误出现在django服务器控制台中

(1_8.W001) The standalone TEMPLATE_* settings were deprecated in Django 1.8 and the TEMPLATES dictionary takes precedence. You must put the values of the following settings into your default TEMPLATES dict: TEMPLATE_DEBUG.

TEMPLATE in Settings 设置中的模板

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        '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',
            ],
        },
    },
]

Settings.py Settings.py

"""
Django settings for blackmarket project.

Generated by 'django-admin startproject' using Django 1.8.6.

For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'ijpwl*f+r5ewyo6-3eorp)&natbb7nh5oh13h&wllhb0o#)gxu'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []



TEMPLATE_CONTEXT_PROCESSORS = (
    "django.contrib.auth.context_processors.auth",
    "django.core.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.media",
    "django.core.context_processors.request",
    "django.core.context_processors.static",
)




# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'products',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'blackmarket.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        '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 = 'blackmarket.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/

STATIC_URL = '/static/'

STATICFILES_FINDERS = (
    "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
)
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static"),
)


# login redirect
LOGIN_REDIRECT_URL = '/detail'
LOGIN_URL = '/login/'
LOGOUT_URL = '/logout/'

You have one of these situations: 您有以下情况之一:

  • You have deployed the files from templates/registration on your local machine to /home/market/src/templates instead of /home/market/src/templates/registration . 您已经将文件从本地计算机上的templates/registration部署到了/home/market/src/templates而不是/home/market/src/templates/registration
  • The same problem exists on your local machine 您的本地计算机上存在相同的问题

So you need to figure out which one it is and adjust accordingly by either creating the registration directory below templates/ and move the files there or change the code that calls for registration/login.html to use login.html . 因此,您需要确定它是哪一个,然后通过在templates/下创建registration目录并在其中移动文件,或更改要求registration/login.html的代码以使用login.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM