配置不正确:导入模块django.middleware.cache.FetchFromCacheMiddlewaredjango.middleware.clickjacking时出错:
我第一次尝试在openshift上部署应用程序。代码使用的是Python 2.7、Django 1.6、MySQL服务器5.6。 我在C:\Users\welcome\resume\wsgi\openshift路径上获得了克隆的默认代码 现在,根据link,首先我们需要在本地运行代码。之后,我们可以将代码推送到openshift 据我所知,我们需要将代码文件添加到此文件夹,并根据需要在settings.py、setup.py等中进行适当的更改 注意:我在wsgi.py文件中没有做任何更改 尝试在本地运行代码时,我遇到错误:配置不正确:导入模块django.middleware.cache.FetchFromCacheMiddlewaredjango.middleware.clickjacking时出错:,django,cloud,openshift,Django,Cloud,Openshift,我第一次尝试在openshift上部署应用程序。代码使用的是Python 2.7、Django 1.6、MySQL服务器5.6。 我在C:\Users\welcome\resume\wsgi\openshift路径上获得了克隆的默认代码 现在,根据link,首先我们需要在本地运行代码。之后,我们可以将代码推送到openshift 据我所知,我们需要将代码文件添加到此文件夹,并根据需要在settings.py、setup.py等中进行适当的更改 注意:我在wsgi.py文件中没有做任何更改 尝试在
Traceback (most recent call last):
File "C:\Python27\lib\wsgiref\handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "C:\Python27\lib\site-packages\django\contrib\staticfiles\handlers.py", l
ine 67, in __call__
return self.application(environ, start_response)
File "C:\Python27\lib\site-packages\django\core\handlers\wsgi.py", line 187, i
n __call__
self.load_middleware()
File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 47, in
load_middleware
mw_class = import_by_path(middleware_path)
File "C:\Python27\lib\site-packages\django\utils\module_loading.py", line 26,
in import_by_path
sys.exc_info()[2])
File "C:\Python27\lib\site-packages\django\utils\module_loading.py", line 21,
in import_by_path
module = import_module(module_path)
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 40, in im
port_module
__import__(name)
ImproperlyConfigured: Error importing module django.middleware.cache.FetchFromCa
cheMiddlewaredjango.middleware.clickjacking: "No module named FetchFromCacheMidd
lewaredjango.middleware.clickjacking"
[06/Aug/2014 12:13:33] "GET / HTTP/1.1" 500 59
Traceback (most recent call last):
File "C:\Python27\lib\wsgiref\handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "C:\Python27\lib\site-packages\django\contrib\staticfiles\handlers.py", l
ine 67, in __call__
return self.application(environ, start_response)
File "C:\Python27\lib\site-packages\django\core\handlers\wsgi.py", line 187, i
n __call__
self.load_middleware()
File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 47, in
load_middleware
mw_class = import_by_path(middleware_path)
File "C:\Python27\lib\site-packages\django\utils\module_loading.py", line 26,
in import_by_path
sys.exc_info()[2])
File "C:\Python27\lib\site-packages\django\utils\module_loading.py", line 21,
in import_by_path
module = import_module(module_path)
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 40, in im
port_module
__import__(name)
ImproperlyConfigured: Error importing module django.middleware.cache.FetchFromCa
cheMiddlewaredjango.middleware.clickjacking: "No module named FetchFromCacheMidd
lewaredjango.middleware.clickjacking"
My Settings.py是:
# -*- coding: utf-8 -*-
# Django settings for OpenShift project.
import imp, os
from django.middleware.clickjacking import XFrameOptionsMiddleware
from django.middleware.common import CommonMiddleware
ON_OPENSHIFT = False
if os.environ.has_key('OPENSHIFT_REPO_DIR'):
ON_OPENSHIFT = True
PROJECT_DIR = os.path.dirname(os.path.realpath(__file__))
if ON_OPENSHIFT:
DEBUG = bool(os.environ.get('DEBUG', False))
if DEBUG:
print("WARNING: The DEBUG environment is set to True.")
else:
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email@example.com'),
)
MANAGERS = ADMINS
if ON_OPENSHIFT:
# os.environ['OPENSHIFT_MYSQL_DB_*'] variables can be used with databases created
# with rhc cartridge add (see /README in this git repo)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': os.path.join(os.environ['OPENSHIFT_DATA_DIR'], 'sqlite3.db'), # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': os.path.join(PROJECT_DIR, 'sqlite3.db'), # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
TIME_ZONE = 'America/Chicago'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = os.environ.get('OPENSHIFT_DATA_DIR', '')
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = ''
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = os.path.join(PROJECT_DIR, '..', 'static')
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
# Examples: "http://foo.com/static/admin/", "/static/admin/".
ADMIN_MEDIA_PREFIX = '/static/admin/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Make a dictionary of default keys
default_keys = { 'SECRET_KEY': 'vm4rl5*ymb@2&d_(gc$gb-^twq9w(u69hi--%$5xrh!xk(t%hw' }
# Replace default keys with dynamic values if we are in OpenShift
use_keys = default_keys
if ON_OPENSHIFT:
imp.find_module('openshiftlibs')
import openshiftlibs
use_keys = openshiftlibs.openshift_secure(default_keys)
# Make this unique, and don't share it with anybody.
SECRET_KEY = use_keys['SECRET_KEY']
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
#'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.cache.FetchFromCacheMiddlewaredjango.middleware.clickjacking',
)
ROOT_URLCONF = 'openshift.urls'
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
os.path.join(PROJECT_DIR, 'templates'),
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
'openshift',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
请告诉我哪里出了问题。此外,如果可能的话,还应提供关于在何处进行更改、在哪些文件中以及在何处准确复制代码的指南 您忘记了“django.middleware.cache.FetchFromCacheMiddleware”之后设置中的“,”
至于要复制什么和修改什么文件,django文档在框架的几乎每个小方面都非常出色和详细:
编辑后:
这:
应该是:
'django.middleware.cache.FetchFromCacheMiddleware',
'django.middleware.clickjacking',
在您的中间件设置中谢谢回复!我查过了,他在。我想知道openshift对文件的编辑。如前所述,首先我们需要在本地运行代码。之后,我们可以将代码推送到openshift。为此,我想知道编辑什么、如何编辑以及将文件放在何处。关于如何在openshift克隆的代码文件夹中本地编辑代码,没有合适的教程。如果您不了解每个文件的功能,那么要编辑的内容和要做的事情都有明确的文档记录,您需要阅读官方文档。显然,您需要一个适用于您的开发环境的普通设置文件,在django应用程序上工作不需要您克隆远程服务器设置。您建议使用任何链接吗?我不知道需要哪些以及所有设置或更改。我可以参考链接吗?
'django.middleware.cache.FetchFromCacheMiddleware',
'django.middleware.clickjacking',