gpt4 book ai didi

Django StaticFiles APP 和 Wsgi

转载 作者:行者123 更新时间:2023-12-01 13:01:36 25 4
gpt4 key购买 nike

这不像其他问题那么简单……至少。设置简单的基于单一目录的静态文件位置不是问题..

https://bitbucket.org/sirex/django-starter/src

这里有一个非常有趣的项目。这个项目使用 distribute 和 buildout 在一个目录中制作整个项目和带有模块的 django。您可以轻松地从开发模式迁移到生产模式等等。您只需要重命名目录,然后在其中键入“make”,就是这样=)那里有手册...

适用于 python 服务器但不适用于 apache mod_wsgi 的情况:默认的静态文件位置是:“var/htdocs/static”。这可以用一个静态目录位置覆盖,例如 apps/myapp/myapp/static/。这适用于 python 网络服务器,但不适用于 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 override 处理其他所有事情.. 不管怎样,请检查那个包,如果你在 linux 或 mac 上,然后自己尝试。它必须工作

附言。 (顺便说一句,bin/django 需要复制为 bin/django.wsgi 并且 etc/apache.conf 是为 apache 生成的 vhost)

如果有人会尝试使用 wsgi 手动启动这个“Starter”,我真的很感激......那么你就会明白一切。=)

编辑:关于 WSGI 如何理解他需要从 django 设置中搜索静态文件的默认位置的任何信息,非常感谢 =)

最佳答案

在官方 mod_wsgi 站点上有很多文档可以帮助您了解如何使用它。这包括如何设置它以提供静态媒体文件。见:

http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines

关于Django StaticFiles APP 和 Wsgi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5576511/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com