没有名为';django.templates';

没有名为';django.templates';,django,python-3.x,django-templates,pycharm,Django,Python 3.x,Django Templates,Pycharm,我使用的是python 3.4、django 1.8。我正在使用pycharm进行开发。运行程序时,我收到“没有名为”django.templates“的模块”错误 设置.py """ Django settings for dj project. Generated by 'django-admin startproject' using Django 1.8.1. For more information on this file, see https://docs.djangoproj

我使用的是python 3.4、django 1.8。我正在使用pycharm进行开发。运行程序时,我收到“没有名为”django.templates“的模块”错误

设置.py

"""
Django settings for dj project.

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

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 = 'uhqkhi7h_w48bz*gnr+_!roaa8@c_)087a(!ees)mn2=n=lv-r'

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

ALLOWED_HOSTS = []


# Application definition

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

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 = 'dj.urls'

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


TEMPLATE_LOADERS = (
    'django.template.loaders.app_directories.load_template_source',
)
WSGI_APPLICATION = 'dj.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/'

TEMPLATE_DIRS = (
    os.path.join(BASE_DIR,  'templates'),
)
blog/url.py

from django.conf.urls import include, url
from . import views

urlpatterns = [
url(r'^$', views.post_list),
]
manage.py

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dj.settings")

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)
post_list.html

<html>
<body>
<p>
    hihiiii
</p>
</body>

</html>
错误


正如错误所提到的,没有像
django.templates
这样的东西

但是,有一个
django.template
。您需要从引用
模板的所有相关行中删除
s

在进行此操作时,还应将
模板加载器
移动到正确的位置(在
模板
设置中)


阅读更多信息。

使用此选项并替换现有值。在上一篇文章中,他告诉您只需要从相关字段中删除“s”。但如果你不明白,那就复制粘贴

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',
            ],

        },
    },
]

我在开始我的第一个django项目时也遇到了同样的例外。。。 我想您可能在pycharm中将模板目录名称从“template”更改为“templates”,但没有意识到pycharm同时在setting.py中更改了templates.context\u处理器的配置。它变了

django.template.context_processors.debug 
django.template.context_processors.request


。这是问题的原因。

如果您不熟悉Pycharm IDE重构,可能会发生这种情况。 您通过重构将“templates”目录重命名为另一个名称。执行此操作时,Pycharm还会重命名“settings.py”中的一些字符串。
因此,右键单击您的“setting.py”->LocalHistory->ShowHistory,然后备份您的“setting.py”。

True,这与将目录名从模板重构为模板有关。需要更正模板下的change settings.py文件(对于我来说,错误是找不到模块“django.template”) 要在模板下进行的更改是从中删除“s”

致:


这是由于Pycharm中的重构造成的。最初,当将目录名“template”更改为“templates”时,我遇到了相同的问题。 要解决此问题,请右键单击settings.py>本地历史记录>显示历史记录>还原。 它还原了由于重构而在设置文件中所做的更改,但将目录名保留为“Templates”。因此,解决这个问题

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',
            ],

        },
    },
]
django.template.context_processors.debug 
django.template.context_processors.request
django.templates.context_processors.debug 
django.templates.context_processors.request
django.templates.context_processors.debug

django.templates.context_processors.request
django.template.context_processors.debug

django.template.context_processors.request