这不像其他人那么简单的问题……至少。设置简单的基于单目录的静态文件位置不是问题..
https://bitbucket.org/sirex/django-starter/src
这里有一个有趣的项目.. 这个项目使用分发和构建来制作整个项目和 django 与一个目录中的模块。您可以轻松地从开发模式迁移到生产模式等等。您所需要的只是重命名目录,然后在其中输入“make”,就是这样=)那里有手册...
适用于 python 服务器且不适用于 apache mod_wsgi 的情况:默认静态文件位置为:“var/htdocs/static”。这可以被一个静态目录位置覆盖,例如apps/myapp/myapp/static/。这适用于 python webserver,但不适用于 wsgi/apache。wsgi 除了默认目录之外什么都看不到.. 示例:http://localhost:8000/static/css/main.css有效,但与 apache 相同的 url 无效。这个文件位于 myproject/apps/myapp/myapp/static/css/main.css 虽然默认的静态目录是 var/htdocs/static =)
据我了解,在 settings.py 中使用 StaticFiles 应用程序进行了这种覆盖
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BUILDOUT_DIR, 'var', 'htdocs', 'static')
STATICFILES_DIRS = (
os.path.join(BUILDOUT_DIR, 'project', 'static'), # <-- why "project" and not "apps" I don't know X_X
)
也许这个不正确,我不知道,但使用 py-server 可以。apache vhost 使用默认位置.. 并设置为“var/htdocs/static”。
也许问题出在 wsgi 脚本中?
#!/usr/local/bin/python2.6
import os,sys
sys.path[0:0] = [
'/usr/local/lib/python2.6/site-packages/',
'/www/webapp/visimes/eggs/PIL-1.1.7-py2.6-freebsd-8.1-RELEASE-amd64.egg',
'/www/webapp/visimes/eggs/South-0.7.3-py2.6.egg',
'/www/webapp/visimes/eggs/django_annoying-0.7.6-py2.6.egg',
'/www/webapp/visimes/eggs/coverage-3.4-py2.6-freebsd-8.1-RELEASE-amd64.egg',
'/www/webapp/visimes/eggs/django_debug_toolbar-0.8.4-py2.6.egg',
'/www/webapp/visimes/eggs/django_extensions-0.6-py2.6.egg',
'/www/webapp/visimes/eggs/django_test_utils-0.3-py2.6.egg',
'/www/webapp/visimes/eggs/ipdb-0.3-py2.6.egg',
'/www/webapp/visimes/eggs/ipython-0.10.1-py2.6.egg',
'/www/webapp/visimes/eggs/djangorecipe-0.21-py2.6.egg',
'/www/webapp/visimes/eggs/zc.recipe.egg-1.3.2-py2.6.egg',
'/www/webapp/visimes/eggs/zc.buildout-1.5.2-py2.6.egg',
'/www/webapp/visimes/eggs/BeautifulSoup-3.2.0-py2.6.egg',
'/www/webapp/visimes/eggs/setuptools-0.6c12dev_r88795-py2.6.egg',
'/www/webapp/visimes/parts/django',
'/www/webapp/visimes',
'/www/webapp/visimes/project', # <-- this one need for monitor.py which i put in there
'/www/webapp/visimes/apps/portal', # <-- startapp.sh script some how forgot to add this dir, it's my default app dir, which must be generated with startapp.sh and added in here..
]
import djangorecipe.wsgi
if __name__ == '__main__':
djangorecipe.manage.main('project.development')
os.environ['DJANGO_SETTINGS_MODULE'] = 'project.development'
import monitor
monitor.start(interval=1.0)
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
我自己添加了最后 4 行。因为我无法启动 apache.. 我猜 djangorecipe.wsgi 应该使用 staticFile 覆盖来处理其他所有事情.. 无论如何,如果你在 linux 或 mac 上,请检查那个包,然后自己尝试一下。它必须工作
附言。(顺便说一句,bin/django 需要复制为 bin/django.wsgi 和 etc/apache.conf 是为 apache 生成的 vhost)
如果有人尝试使用 wsgi 手动启动这个“Starter”,我真的很高兴......那么你就会明白一切。=)
编辑:任何关于 WSGI 如何理解他需要从 django 设置的默认位置搜索静态文件的位置的任何信息,都非常感谢 =)