[Fixed]-Django Tutorial: name 'HttpResponse' is not defined

73👍

from django.http import HttpResponse

in your views file at the top

8👍

Put this import in your poll/views.py before using HttpResponse.

from django.http import HttpResponse

4👍

from django.http import HttpResponse
add this line on the top of polls/views.py file. I am new too, and had the same error. good Luck and i see u around.

1👍

in your polls/views.py

By default is :

from django.shortcuts import render

change to:

from django.shortcuts import render,HttpResponse

this will call the HttpResponse class

0👍

I had imported HttpResponse and still got this error.

If you use Apache server as your primary server for web, try restarting Apache and reloading the page.

0👍

In my case the import was there, but when I called HttpsResponse I called it with small h as a typo instead of the capital H

from django.http import HttpResponse
def home(request):
      return HttpResponse("Hello!") #==> This one was with httpResponse so the same error been received.

-1👍

For me it was because I used singe quotes (‘) instead of double quotes (“)

-1👍

  1. Check your import statement.
  2. Check your function. I had “HttpsResponse” instead of “HttpResponse”

Good luck.

👤Freddy

Leave a comment