为什么 DEBUG=False 设置使我的 django 静态文件访问失败? [英] Why does DEBUG=False setting make my django Static Files Access fail?

查看:34
本文介绍了为什么 DEBUG=False 设置使我的 django 静态文件访问失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Django 作为我的主力构建一个应用程序.到目前为止一切都很好 - 指定的 db 设置、配置的静态目录、url、视图等.但是当我想要呈现我自己的漂亮和自定义的 404.html 和 500.html 页面时,麻烦就开始了.

我阅读了有关自定义错误处理的文档,并在 UrlsConf 中设置了必要的配置,创建了相应的视图并将 404.html 和 500.html 添加到我的应用程序的模板目录(也在 settings.py 中指定).

但是文档说您实际上可以查看自定义错误视图,直到 Debug 关闭,所以我确实将其关闭以测试我的东西,这就是东西变得疯狂的时候!

我不仅无法查看自定义 404.html(实际上,它已加载,但因为我的每个错误页面都包含图形错误消息 - 作为一些漂亮的图像),错误页面的来源加载,但没有其他内容负载!甚至没有链接的 CSS 或 Javascript!

通常,一旦我设置了 DEBUG = False,所有视图都会加载,但任何链接的内容(CSS、Javascript、图像等)都不会加载!发生了什么?是否缺少有关静态文件和 DEBUG 设置的内容?

解决方案

关闭调试后,Django 将不再为您处理静态文件 - 您的生产 Web 服务器(Apache 或其他东西)应该负责.

>

Am building an app using Django as my workhorse. All has been well so far - specified db settings, configured static directories, urls, views etc. But trouble started sneaking in the moment I wanted to render my own beautiful and custom 404.html and 500.html pages.

I read the docs on custom error handling, and set necessary configurations in UrlsConf, created corresponding views and added the 404.html and the 500.html to my app's template directory (specified in the settings.py too).

But the docs say you can actually view custom error views until Debug is Off, so I did turn it off to test my stuff, and that's when stuff goes berserk!

Not only do I fail to view the custom 404.html (actually, it loads, but because my error pages each contain a graphic error message -as some nice image), the source of the error page loads, but nothing else loads! Not even linked CSS or Javascript!

Generally, once I set DEBUG = False, all views will load, but any linked content (CSS, Javascript, Images, etc) wont load! What's happening? Is there something am missing, concerning static files and the DEBUG setting?

解决方案

With debug turned off Django won't handle static files for you any more - your production web server (Apache or something) should take care of that.

这篇关于为什么 DEBUG=False 设置使我的 django 静态文件访问失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆