Django AttributeError Type Object Http404 Has No Attribute Has_Header

Do you like this?

This short post shows you how to fix this problem in Django.


This error occurs when you try to return an object of Http404 for your view. All you need to do is to change from return Http404 to raise Http404.

The reason is that Django views expect to have HttpResponse as the return value. And if you take a good look at the class declaration of HttpResponse in django.http, you can see that it contains the method has_header().

class HttpResponse(object):

    status_code = 200

    def __init__(self, content='', mimetype=None, status=None,

    def has_header(self, header):
        """Case-insensitive check for a header."""
        return self._headers.has_key(header.lower())

comments powered by Disqus