我尝试在django-cms安装上创建3个站点。我在django-cms 3网站的管理中注册:
我正确 cmsdjango 。但是当我尝试访问网站“ site01 ”或“ site02 ”时,出现错误“ 500内部服务器错误”。并在apache错误日志中:
[Wed Mar 05 08:30:53.238161 2014] [:error] [pid 3064] [remote 127.0.0.1:15543] mod_wsgi (pid=3064): Exception occurred processing WSGI script '/home/oss974/www/cmsdjango/cmsdjango/wsgi_site01.py'.
[Wed Mar 05 08:30:53.238242 2014] [:error] [pid 3064] [remote 127.0.0.1:15543] Traceback (most recent call last):
[Wed Mar 05 08:30:53.238257 2014] [:error] [pid 3064] [remote 127.0.0.1:15543] File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 255, in __call__
[Wed Mar 05 08:30:53.238365 2014] [:error] [pid 3064] [remote 127.0.0.1:15543] response = self.get_response(request)
[Wed Mar 05 08:30:53.238376 2014] [:error] [pid 3064] [remote 127.0.0.1:15543] File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 178, in get_response
[Wed Mar 05 08:30:53.238401 2014] [:error] [pid 3064] [remote 127.0.0.1:15543] response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Wed Mar 05 08:30:53.238410 2014] [:error] [pid 3064] [remote 127.0.0.1:15543] File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 220, in handle_uncaught_exception
[Wed Mar 05 08:30:53.238423 2014] [:error] [pid 3064] [remote 127.0.0.1:15543] if resolver.urlconf_module is None:
[Wed Mar 05 08:30:53.238431 2014] [:error] [pid 3064] [remote 127.0.0.1:15543] File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 342, in urlconf_module
[Wed Mar 05 08:30:53.238445 2014] [:error] [pid 3064] [remote 127.0.0.1:15543] self._urlconf_module = import_module(self.urlconf_name)
[Wed Mar 05 08:30:53.238453 2014] [:error] [pid 3064] [remote 127.0.0.1:15543] File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
[Wed Mar 05 08:30:53.238473 2014] [:error] [pid 3064] [remote 127.0.0.1:15543] __import__(name)
[Wed Mar 05 08:30:53.238485 2014] [:error] [pid 3064] [remote 127.0.0.1:15543] ImportError: No module named site01_urls
以下是我使用的配置:
项目文件夹
/home/raphael/www/cmsdjango
文件夹结构
├── cmsdjango
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── site01_urls.py
│ ├── site02_urls.py
│ ├── media
│ ├── settings_site01.py
│ ├── settings_site02.py
│ ├── settings.py
│ ├── settings.pyc
│ ├── static
│ ├── templates
│ │ ├── base.html
│ │ ├── template_1.html
│ │ └── template_2.html
│ ├── urls.py
│ ├── urls.pyc
│ ├── wsgi_site01.py
│ ├── wsgi_site02.py
│ ├── wsgi.py
│ └── wsgi.pyc
└── manage.py
'设置'文件
/home/raphael/www/cmsdjango/cmsdjango/settings.py :
# -*- coding: utf-8 -*-
import os
gettext = lambda s: s
PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email@example.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'cmsdjango',
'USER': 'admin',
'PASSWORD': 'password',
'HOST': '',
'PORT': '',
}
}
ALLOWED_HOSTS = []
TIME_ZONE = 'America/Chicago'
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
USE_I18N = True
USE_L10N = True
USE_TZ = True
MEDIA_ROOT = os.path.join(PROJECT_PATH, "media")
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(PROJECT_PATH, "static")
STATIC_URL = '/static/'
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.
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
SECRET_KEY = '&vqh+-mqm9+3^yka2(m(p&n-rrqs#*@+ejh%g3*0qquhfmtpqd'
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.doc.XViewMiddleware',
'django.middleware.common.CommonMiddleware',
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.user.CurrentUserMiddleware',
'cms.middleware.toolbar.ToolbarMiddleware',
'cms.middleware.language.LanguageCookieMiddleware',
)
ROOT_URLCONF = 'cmsdjango.urls'
WSGI_APPLICATION = 'cmsdjango.wsgi.application'
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_PATH, "templates"),
)
CMS_TEMPLATES = (
('template_1.html', 'Template One'),
('template_2.html', 'Template Two'),
)
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',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'cms',
'mptt',
'menus',
'south',
'sekizai',
'cms.plugins.file',
'cms.plugins.flash',
'cms.plugins.googlemap',
'cms.plugins.link',
'cms.plugins.picture',
# 'cms.plugins.snippet',
'cms.plugins.teaser',
'cms.plugins.text',
'cms.plugins.video',
'cms.plugins.twitter',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.i18n',
'django.core.context_processors.request',
'django.core.context_processors.media',
'django.core.context_processors.static',
'cms.context_processors.media',
'sekizai.context_processors.sekizai',
)
LANGUAGES = [
('en', 'English'),
]
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
/home/raphael/www/cmsdjango/cmsdjango/settings_site01.py:
from settings import *
SITE_ID = 2
ROOT_URLCONF = 'site01_urls'
DEBUG = False
/home/raphael/www/cmsdjango/cmsdjango/settings_site02.py:
from settings import *
SITE_ID = 3
ROOT_URLCONF = 'site02_urls'
DEBUG = False
'网址'文件
/home/raphael/www/cmsdjango/cmsdjango/urls.py :
from django.conf.urls.defaults import *
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
from django.conf import settings
admin.autodiscover()
urlpatterns = i18n_patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('cms.urls')),
)
if settings.DEBUG:
urlpatterns = patterns('',
url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
url(r'', include('django.contrib.staticfiles.urls')),
) + urlpatterns
/home/raphael/www/cmsdjango/cmsdjango/site01_.py:
from django.conf.urls.defaults import *
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
from django.conf import settings
admin.autodiscover()
urlpatterns = i18n_patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('cms.urls')),
)
if settings.DEBUG:
urlpatterns = patterns('',
url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
url(r'', include('django.contrib.staticfiles.urls')),
) + urlpatterns
/home/raphael/www/cmsdjango/cmsdjango/site02_urls.py:
from django.conf.urls.defaults import *
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
from django.conf import settings
admin.autodiscover()
urlpatterns = i18n_patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('cms.urls')),
)
if settings.DEBUG:
urlpatterns = patterns('',
url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
url(r'', include('django.contrib.staticfiles.urls')),
) + urlpatterns
'wsgi'文件
/home/raphael/www/cmsdjango/cmsdjango/wsgi.py :
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cmsdjango.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
/home/raphael/www/cmsdjango/cmsdjango/wsgi_site01.py:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cmsdjango.settings_site01")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
/home/raphael/www/cmsdjango/cmsdjango/wsgi_site02.py:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cmsdjango.settings_site02")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
'主持人'文件
/ etc / hosts :
...
127.0.0.1 cmsdjango
127.0.0.1 site01
127.0.0.1 site02
...
''virtualhost'文件
/etc/apache2/sites-available/cmsdjango.conf :
<VirtualHost *:80>
ServerName cmsdjango
ServerAlias cmsdjango
DocumentRoot /home/raphael/www/cmsdjango
<Directory /home/raphael/www/cmsdjango>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
WSGIDaemonProcess cmsdjango processes=2 threads=15 display-name=%{GROUP} python-path=/home/raphael/www/cmsdjango
WSGIProcessGroup cmsdjango
WSGIScriptAlias / /home/raphael/www/cmsdjango/cmsdjango/wsgi.py
<Directory /home/raphael/www/cmsdjango/cmsdjango>
Order allow,deny
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/cmsdjango_error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/cmsdjango_access.log combined
</VirtualHost>
/etc/apache2/sites-available/site01.conf :
<VirtualHost *:80>
ServerName site01
ServerAlias site01
DocumentRoot /home/raphael/www/cmsdjango
<Directory /home/raphael/www/cmsdjango>
<Files wsgi_site01.py>
Order deny,allow
Allow from all
</Files>
</Directory>
WSGIDaemonProcess site01 processes=2 threads=15 display-name=%{GROUP} python-path=/home/raphael/www/cmsdjango
WSGIProcessGroup site01
WSGIScriptAlias / /home/raphael/www/cmsdjango/cmsdjango/wsgi_site01.py
<Directory /home/raphael/www/cmsdjango/cmsdjango>
Order allow,deny
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/cmsdjango_error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/cmsdjango_access.log combined
</VirtualHost>
/etc/apache2/sites-available/site02.conf :
<VirtualHost *:80>
ServerName site02
ServerAlias site02
DocumentRoot /home/raphael/www/cmsdjango
<Directory /home/raphael/www/cmsdjango>
<Files wsgi_site02.py>
Order deny,allow
Allow from all
</Files>
</Directory>
WSGIDaemonProcess site02 processes=2 threads=15 display-name=%{GROUP} python-path=/home/raphael/www/cmsdjango
WSGIProcessGroup site02
WSGIScriptAlias / /home/raphael/www/cmsdjango/cmsdjango/wsgi_site02.py
<Directory /home/raphael/www/cmsdjango/cmsdjango>
Order allow,deny
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/cmsdjango_error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/cmsdjango_access.log combined
</VirtualHost>