- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试使用virtualenv,而evrythings出错了...
我停用了所有virtualenv(使用deactavite)。
当我尝试启动时: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
"""
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
最佳答案
从您的设置中删除此行:
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCP
TEMPLATE_CONTEXT_PROCESSORS
。无法再导入它。
context_processors
设置中定义了
TEMPLATES
,因此不再需要
TEMPLATE_CONTEXT_PROCESSORS
。
关于django - 无法导入名称TEMPLATE_CONTEXT_PROCESSORS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39315348/
我需要在所有页面中显示一些统计数字,所以我决定使用上下文处理器。但我刚刚发现我的函数在每次页面加载时都会被调用 2 到 7 次。我在函数内执行了 4 次查询,因此性能非常差。每个页面加载最多可能需要
遵循 docs If TEMPLATE_CONTEXT_PROCESSORS contains this processor, every RequestContext will contain th
我没有 TEMPLATE_CONTEXT_PROCESSORS在我的默认设置中! TEMPLATE_CONTEXT_PROCESSORS = ( 'django.contrib.auth.co
我尝试使用 django-endless-pagination https://django-endless-pagination.readthedocs.io/en/latest/start.htm
您好,我正在将项目从 Django 1.9.12 迁移到 Django2.0我还没写,是一个不再在我们企业工作的同事留下的 安装Django2后 from django.conf.global_set
安装了 Django 1.10.4 并启动了一个名为 test_py 的项目。之后创建了一个名为 test_app1 的应用。 在创建应用程序后,计划创建一个安装程序以将其作为标准独立应用程序运行。
我正在关注 django 报告生成器快速入门手册: pip 安装 django-report-builder - 完成 将 report_builder 添加到 INSTALLED_APPS - 完成
我正在将一个项目升级到 Django 1.10,它的代码如下: from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS
我是一名优秀的程序员,十分优秀!