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


from django.http import HttpResponse

in your views file at the top


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

from django.http import HttpResponse


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.


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


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.


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.


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


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

Good luck.


Leave a comment