我正在尝试第一次在openshift上部署应用程序。代码使用的是Python 2.7,Django 1.6,MySQL Server 5.6。 我在C:\ Users \ welcome \ resume \ wsgi \ openshift路径上获得了克隆的默认代码。
现在,根据https://www.openshift.com/developers/deploying-and-building-applications链接,首先我们需要在本地运行我们的代码。之后我们可以将代码推送到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"
我的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,
},
}
}
请告诉我哪里出错了。此外,如果可能的话,还可以指导何处进行更改以及在哪些文件中以及在何处准确复制代码。
答案 0 :(得分:0)
你在“django.middleware.cache.FetchFromCacheMiddleware”之后的设置中忘记了一个“,”
至于要复制的内容和要修改的文件,django文档几乎在框架的每个方面都非常精细和详细: https://docs.djangoproject.com/en/1.6/
编辑后:
此:
'django.middleware.cache.FetchFromCacheMiddlewaredjango.middleware.clickjacking',
应该是:
'django.middleware.cache.FetchFromCacheMiddleware',
'django.middleware.clickjacking',
在您的MIDDLEWARE设置中