gpt4 book ai didi

python - ./manage.py 测试不提供静态文件?

转载 作者:太空宇宙 更新时间:2023-11-04 03:22:18 25 4
gpt4 key购买 nike

我在一个项目中发现了以下代码,删除它会导致测试失败:

if 'test' in sys.argv:
urlpatterns += patterns('',
(r'^static/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': os.path.join(settings.BASE_DIR, 'viewer/templates/static')}),
)

出于某种原因,./manage.py test 不提供没有此行的静态文件,即使它在 ./manage.py runserver 上运行良好。为什么会这样?

最佳答案

之所以需要为 manage.py test 指定那些行,是因为提供静态文件不是默认的 django 行为。

如果您通过manage.py runserver 运行服务器,static content is only served if DEBUG=True .

提供此功能是为了在开发模式下为用户提供帮助,不建议在生产中使用。

来自上面的链接:

Serving the files

In addition to these configuration steps, you’ll also need to actually serve the static files.

During development, if you use django.contrib.staticfiles, this will be done automatically by runserver when DEBUG is set to True (see django.contrib.staticfiles.views.serve()).

This method is grossly inefficient and probably insecure, so it is unsuitable for production.

See Deploying static files for proper strategies to serve static files in production environments.

关于python - ./manage.py 测试不提供静态文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34295003/

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