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

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

问题描述

使用Django构建一个应用程序作为我的主力。所有这一切已经很好 - 指定的数据库设置,配置的静态目录,网址,视图等。但是,在我想要渲染我自己的美丽和自定义的404.html和500.html页面的时候,麻烦开始潜行。



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



但文档说可以实际查看自定义错误视图,直到调试关闭,所以我确实把它关闭了,以测试我的东西,那就是当事情变得疯狂时!



不仅我无法查看自定义的404.html(实际上,它加载,但是因为我的错误页面都包含图形错误消息 - 一些很好的图像),erro页面的来源加载,但没有其他的东西加载!一般来说,一旦设置了 DEBUG = False ,所有的视图都会被加载,但是任何链接的内容(CSS,Javascript,图像等)都不会加载!发生了什么?有没有关于静态文件调试设置

解决方案

调试关闭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 erro 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 about 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天全站免登陆