姜戈 404 困境
我的 404 设置中有一个错误。我知道这一点,因为当我尝试访问某个不存在的页面时,我会收到服务器错误模板。但该模板毫无用处,因为它没有给我任何调试信息。为了获得 django 的调试页面,我需要在设置文件中设置 DEBUG=True 。但如果我这样做,错误就不会出现,因为 django 不会尝试访问我的错误 404 设置。那么你们觉得怎么样?
这是在我的根 url 文件中: handler404 = 'portal.blog.views.handlenotfound'
这是在portal.blog.views.handlenotfound中:
def handlenotfound(request): global common_data datas = { 'tags' : Tag.objects.all(), 'date_list' : Post.objects.filter(yayinlandi=True).dates("pub_date","year") } data.update(common_data) return render_to_response("404.html",datas)
Edit:
我想我还需要返回 HttpResponseNotFound 对吗?
I have a bug in my 404 setup. I know that because, when I try to reach some page which doesn't exist, I get my server error template. But that templates is useless because it doesn't give me any debug info. In order to get django's debug page, I need to set DEBUG=True in settings file. But if I do that, bug doesn't appear because django doesn't try to access my buggy 404 setup. So what do you guys think?
This is in my root urls file:handler404 = 'portal.blog.views.handlenotfound'
And this is in portal.blog.views.handlenotfound:
def handlenotfound(request): global common_data datas = { 'tags' : Tag.objects.all(), 'date_list' : Post.objects.filter(yayinlandi=True).dates("pub_date","year") } data.update(common_data) return render_to_response("404.html",datas)
Edit:
I guess I also need to return a HttpResponseNotFound right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我必须调试此类错误,我会
暂时将处理程序转换为由自定义 url 提供服务的简单视图,这样 django 的内部机制就不会妨碍,或者
(暂时)将处理程序代码包装在 try.. except 块中以记录您可能遇到的任何错误missed
无论如何,您确定如果 DEBUG=true 则不会调用您的处理程序吗?
If I had to debug this kind of errors, I would either
temporarily turn the handler into a simple view served by a custom url, so that django's internal mechanisms don't get into the way, or
(temporarily) wrap the handler code in a try..except block to log any error you may have missed
Anyway, are you sure your handler doesn't get called if DEBUG=true?
data.update(common_data)
应为datas.update(common_data)
。(顺便说一句,data 已经是复数形式:单数是 datum。)
data.update(common_data)
should bedatas.update(common_data)
.(Incidentally, data is already plural: the singular is datum.)