我有一个适用于嵌入式服务器的django项目,但是当我尝试在Apache / mod_wsgi上使用它时,找不到管理页面的静态文件(/ static / admin / css)(404)。以下是我的设置:
MEDIA_ROOT = ''
MEDIA_URL = ''
STATIC_ROOT = '/var/www/wsgi/myproject/static'
STATIC_URL = '/static/'
ADMIN_MEDIA_PREFIX = '/static/admin/'
STATICFILES_DIRS = ()
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
TEMPLATE_CONTEXT_PROCESSORS = (
"socialauth.context_processors.facebook_api_key",
'django.core.context_processors.media',
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.request",
"django.core.context_processors.static",
)
ROOT_URLCONF = 'myproject.urls'
TEMPLATE_DIRS = ('/var/www/wsgi/myproject/templates',)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'myproject.myapp',
)
我也尝试过
sudo python ./manage.py collectstatic
但没有运气。
答案 0 :(得分:1)
你的apache virtualhost配置是什么样的?您应该为Alias
路径添加STATIC_ROOT
指令。
这些方面的东西:
Alias /static [project-path]/static
Alias /media [project-path]/media
<Directory [project-path]/static>
Order deny,allow
Allow from all
</Directory>
<Directory [project-path]/media>
Order deny,allow
Allow from all
</Directory>
正如您所写,每次要在生产中部署新的静态文件时,都需要运行./manage collectstatic
。