无法定义默认缓存 Django
Can't define default cache Django
我正在尝试在 Django 中设置缓存,但它不允许我定义默认缓存。
我不太关心我使用的是什么类型的缓存(我已经尝试过 Filesystem and Database 缓存。)
但即使复制粘贴他们的示例代码,错误检查器也会告诉我:
?: (caches.E001) You must define a 'default' cache in your CACHES setting.
我还尝试将 CACHES 设置放在 settings.py 文件的底部,以确保初始化 CACHES 设置可能依赖的任何内容。
我的代码如下:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': '/var/tmp/django_cache',
}
}
完整的错误信息是:
Unhandled exception in thread started by <function check_errors.
<locals>.wrapper at 0x0436A300>
Traceback (most recent call last):
File "C:\Users\Kasper\Documents\kasperfred-blog\kasperfred-blog\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "C:\Users\Kasper\Documents\kasperfred-blog\kasperfred-blog\lib\site-packages\django\core\management\commands\runserver.py", line 116, in inner_run
self.check(display_num_errors=True)
File "C:\Users\Kasper\Documents\kasperfred-blog\kasperfred-blog\lib\site-packages\django\core\management\base.py", line 472, in check
raise SystemCheckError(msg)
django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:
ERRORS:
?: (caches.E001) You must define a 'default' cache in your CACHES setting.
大部分设置文件(编辑掉密钥)
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
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.9/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'Sorry'
# 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',
'posts',
# Third party
'trumbowyg',
'crispy_forms',
'taggit',
'imagefit',
]
CRISPY_TEMPLATE_PACK = 'bootstrap3'
TAGGIT_CASE_INSENSITIVE = True
# Image fit settings
IMAGEFIT_ROOT = "public"
IMAGEFIT_PRESETS = {
'card_small': {'width': 64, 'height': 64, 'crop': True},
'my_preset1': {'width': 300, 'height': 220},
'my_preset2': {'width': 100},
}
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'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',
]
ROOT_URLCONF = 'kasperfred_blog.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 = 'kasperfred_blog.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.9/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.9/howto/static-files/
STATIC_URL = '/static/'
MEDIA_URL = "/media/"
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
#'/var/www/static/',
]
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static_cdn")
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), "media_cdn")
# Cache
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': '/var/tmp/django_cache',
}
}
此问题是由 imagefit
引起的,它会在加载时覆盖 CACHES
设置:
settings.CACHES = {
IMAGEFIT_CACHE_BACKEND_NAME: {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': os.path.join(tempfile.gettempdir(), 'django_imagefit')
}
}
显然问题出在 recently fixed - 所以如果您可以获得最新版本,它应该可以解决问题。
我无法从 Github 存储库判断进行此更改后 PyPi 上是否发布了新版本。
我正在尝试在 Django 中设置缓存,但它不允许我定义默认缓存。 我不太关心我使用的是什么类型的缓存(我已经尝试过 Filesystem and Database 缓存。)
但即使复制粘贴他们的示例代码,错误检查器也会告诉我:
?: (caches.E001) You must define a 'default' cache in your CACHES setting.
我还尝试将 CACHES 设置放在 settings.py 文件的底部,以确保初始化 CACHES 设置可能依赖的任何内容。
我的代码如下:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': '/var/tmp/django_cache',
}
}
完整的错误信息是:
Unhandled exception in thread started by <function check_errors.
<locals>.wrapper at 0x0436A300>
Traceback (most recent call last):
File "C:\Users\Kasper\Documents\kasperfred-blog\kasperfred-blog\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "C:\Users\Kasper\Documents\kasperfred-blog\kasperfred-blog\lib\site-packages\django\core\management\commands\runserver.py", line 116, in inner_run
self.check(display_num_errors=True)
File "C:\Users\Kasper\Documents\kasperfred-blog\kasperfred-blog\lib\site-packages\django\core\management\base.py", line 472, in check
raise SystemCheckError(msg)
django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:
ERRORS:
?: (caches.E001) You must define a 'default' cache in your CACHES setting.
大部分设置文件(编辑掉密钥)
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
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.9/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'Sorry'
# 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',
'posts',
# Third party
'trumbowyg',
'crispy_forms',
'taggit',
'imagefit',
]
CRISPY_TEMPLATE_PACK = 'bootstrap3'
TAGGIT_CASE_INSENSITIVE = True
# Image fit settings
IMAGEFIT_ROOT = "public"
IMAGEFIT_PRESETS = {
'card_small': {'width': 64, 'height': 64, 'crop': True},
'my_preset1': {'width': 300, 'height': 220},
'my_preset2': {'width': 100},
}
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'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',
]
ROOT_URLCONF = 'kasperfred_blog.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 = 'kasperfred_blog.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.9/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.9/howto/static-files/
STATIC_URL = '/static/'
MEDIA_URL = "/media/"
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
#'/var/www/static/',
]
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static_cdn")
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), "media_cdn")
# Cache
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': '/var/tmp/django_cache',
}
}
此问题是由 imagefit
引起的,它会在加载时覆盖 CACHES
设置:
settings.CACHES = {
IMAGEFIT_CACHE_BACKEND_NAME: {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': os.path.join(tempfile.gettempdir(), 'django_imagefit')
}
}
显然问题出在 recently fixed - 所以如果您可以获得最新版本,它应该可以解决问题。
我无法从 Github 存储库判断进行此更改后 PyPi 上是否发布了新版本。