Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot import name TEMPLATE_CONTEXT_PROCESSORS

I tried to use virtualenv and evrythings gone wrong ...

I desactived (with deactavite) all virtualenv .

When i try to launch : python manage.py runserver

I got this error message :

 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

my path PYTHON_PATH="/usr/lib/python2.7/dist-packages"

my django version: 1.10

settings.py file

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

If somebody have a idea, thank you.

like image 602
Jean-François Avatar asked Sep 04 '16 09:09

Jean-François


1 Answers

Remove this line from your settings:

from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCP

TEMPLATE_CONTEXT_PROCESSORS was deprecated in Django 1.8 and removed in Django 1.10. It's not possible to import it anymore.

You have already defined context_processors in your TEMPLATES setting, so you don't need TEMPLATE_CONTEXT_PROCESSORS anymore.

like image 100
Alasdair Avatar answered Nov 11 '22 02:11

Alasdair