我正在尝试使用mod_wsgi和Apache2部署我的Django项目,但我无法弄清楚为什么管理CSS样式没有加载。我使用Django-admin-tools作为应用程序来增强管理界面的外观,并且它在开发服务器上运行良好,但在部署期间出现了样式问题。
服务器上的项目路径是:
'/srv/www/myapp/'
'/srv/www/myapp/media/admin_tools/css|js|images'
setting.py包含:
MEDIA_ROOT = '/srv/www/myapp/media/'
# also tried MEDIA_ROOT = '/srv/www/myapp/media/admin_tools/'
MEDIA_URL = 'http://myserverip:80/media/'
STATIC_ROOT = '/srv/www/myapp/static'
STATIC_URL = '/static/'
ADMIN_MEDIA_PREFIX = '/media/'
# also tried ADMIN_MEDIA_PREFIX = '/media/admin_tools/'
STATICFILES_DIRS = (
'/srv/www/myapp/projectstatic' )
TEMPLATE_DIRS = (
'/srv/www/myapp/templates' )
INSTALLED_APPS = (
'admin_tools',
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
'django.contrib.auth',
#Many other applications )
ADMIN_TOOLS_INDEX_DASHBOARD = 'myapp.dashboard.CustomIndexDashboard'
ADMIN_TOOLS_APP_INDEX_DASHBOARD = 'myapp.dashboard.CustomAppIndexDashboard'
ADMIN_TOOLS_THEMING_CSS = '/srv/www/myapp/media/admin_tools/css/theming.css'
ADMIN_TOOLS_MENU = 'myapp.menu.CustomMenu'
urls.py:
urlpatterns = patterns('',
url(r'^admin_tools/', include('admin_tools.urls')),
)
django.wsgi :(此文件的路径为'/srv/www/myapp/apache/django.wsgi')
import os
import sys
path = '/srv/www/'
if path not in sys.path:
sys.path.insert(0, '/srv/www/')
sys.path = ['/srv/www/myapp'] + sys.path
sys.path.append('/usr/local/lib/python2.7/dist-packages/registration/backends')
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
print >> sys.stderr, sys.path
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
答案 0 :(得分:0)
在目录'/ srv / www / myapp / apache /'中,您可能想要创建另一个conf文件。对于这个例子,我将使用apache_django_wsgi.conf。在该文件中获取/etc/apache2/httpd.conf中的所有内容并复制到apache_django_wsgi.conf并将其替换为
LoadModule wsgi_module modules/mod_wsgi.so
include "/srv/www/myapp/apache/apache_django_apache.conf"
现在提供管理文件: 在apache_django_apache.conf中为管理文件添加和别名: 示例
Alias /admin_media/ /path/to/admin_media
<Directory "admin_media">
Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing
</Directory>