yasar
yasar

Reputation: 13728

Django 404 dilemma

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?

Upvotes: 1

Views: 434

Answers (2)

ftartaggia
ftartaggia

Reputation: 541

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?

Upvotes: 2

Ismail Badawi
Ismail Badawi

Reputation: 37167

data.update(common_data) should be datas.update(common_data).

(Incidentally, data is already plural: the singular is datum.)

Upvotes: 2

Related Questions