1

我正在尝试使用 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'

网址.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()
4

1 回答 1

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>
于 2012-04-09T04:17:18.323 回答