Django – AttributeError: ‘Http404’ object has no attribute ‘status_code’

If you getting this error, it might be because you are returning Http404 instead of raising it.
you need to raise django.http.Http404, not return it.

example code :

from django.http import Http404

def my_view(request):
    try:
        my_object = MyModel.objects.get(pk=1)
    except MyModel.DoesNotExist:
        raise Http404

One thought on “Django – AttributeError: ‘Http404’ object has no attribute ‘status_code’

  1. Pingback: Handling two Django models in a single POST | Shashank's Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s