我在 ubuntu 上安装了带有 MySQL 和 mod_wsgi 的 Django 1.5.1。在我将我的项目从本地机器导入到服务器后,我通过访问所有 URL 得到了这个错误:
**ImproperlyConfigured at /**
Empty static prefix not permitted
Request Method: GET
Request URL: http://50.7.177.122/
Django Version: 1.5.1
Exception Type: ImproperlyConfigured
Exception Value:
Empty static prefix not permitted
Exception Location: /srv/projects/venv/lib/python2.7/site-packages/django/conf/urls/static.py in static, line 22
Python Executable: /usr/bin/python
Python Version: 2.7.3
Python Path:
['/srv/projects/app/danial',
'/srv/projects/app',
'/srv/projects/venv/lib/python2.7/site-packages',
'/srv/projects/venv/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
'/srv/projects/venv/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg',
'/srv/projects/venv/lib/python2.7/site-packages',
'/srv/projects/venv/lib/python2.7/site-packages/PIL',
'/usr/local/lib/python2.7/dist-packages/virtualenv-1.9.1-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/virtualenvwrapper-4.0-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/stevedore-0.8-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/virtualenv_clone-0.2.4-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/pip-1.3.1-py2.7.egg',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages']
我的项目名称是 danial,它包含一个应用程序、画廊。我的静态文件夹位于 /danial/gallery/static 我很困惑。这是我项目中所有与静态相关的行:
###settings.py
STATIC_ROOT = '/srv/projects/app/danial/gallery/static/'
STATIC_URL = '/static/'
STATICFILES_DIRS = ('/srv/projects/app/danial/gallery/static/',)
###apache setting
Alias /static/ /srv/projects/venv/lib/python2.7/site-packages/django/contrib/admin/static/
###urls.py
from danial import settings
from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns += staticfiles_urlpatterns()
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
它在我的本地运行良好。我应该知道什么?