无法导入名称TEMPLATE_CONTEXT_PROCESSORS

时间:2016-09-04 09:14:09

标签: django python-2.7 templates

我试图使用virtualenv和evrythings出错......

我决定(使用deactavite)所有virtualenv。

当我尝试启动时:python manage.py runserver

我收到此错误消息:

 Traceback (most recent call last):   File "manage.py", line 11, in
 <module>
     execute_from_command_line(sys.argv)   File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py",
 line 367, in execute_from_command_line
     utility.execute()   File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py",
 line 316, in execute
     settings.INSTALLED_APPS   File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line
 53, in __getattr__
     self._setup(name)   File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line
 41, in _setup
>     self._wrapped = Settings(settings_module)   File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line
 97, in __init__
     mod = importlib.import_module(self.SETTINGS_MODULE)   File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
     __import__(name)   File "/home/jf/mysite/mysite/settings.py", line 68, in <module>
     from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCP ImportError: cannot import name
 TEMPLATE_CONTEXT_PROCESSORS
我的道路 PYTHON_PATH = “/ usr / lib中/ python2.7 / DIST-包”

我的django版本:1.10

settings.py文件

"""
Django settings for mysite project.

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

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 = 'telo@^)(b_8j=s^507(u_zq)b71s$rcn=xl_r%36fs-e923*45'

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

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [

    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

#    'django_dynamic_views',
    'teckno',
    'polls',
    'suit',
    'django.contrib.admin',
    'bootstrap3',
]

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

from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCP

TEMPLATE_CONTEXT_PROCESSORS = TCP + (
    'django.core.context_processors.request',
)

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ['','teckno', 'demo'],
        '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.request', 
                "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.static",
                "django.core.context_processors.tz",
                "django.contrib.messages.context_processors.messages",
                'django.core.context_processors.request',

            ],
        },
    },
]

WSGI_APPLICATION = 'mysite.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 = 'fr-fr'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Modif

#STATIC_ROOT = "/home/jf/mysite/mysite"
ROOT_PATH = os.path.dirname(__file__)
STATIC_ROOT = os.path.join(ROOT_PATH, 'static')

STATIC_URL = '/static/'

# MOFIF JF

# https://docs.djangoproject.com/fr/1.10/ref/settings/#append-slash
APPEND_SLASH=False

如果有人有想法,谢谢。

1 个答案:

答案 0 :(得分:13)

从您的设置中删除此行:

from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCP
在Django 1.8和removed in Django 1.10中弃用了{p> TEMPLATE_CONTEXT_PROCESSORS。它不再可能导入它。

您已在context_processors设置中定义了TEMPLATES,因此您不再需要TEMPLATE_CONTEXT_PROCESSORS