Django Tutorial: name 'HttpResponse' is not defined

Viewed 28371

I am learning Django via their tutorial for getting started. I have looked at other Django Tutorial errors and did not see this one (although I did not search every listing).

I have made the changes to mysite/urls.py and polls/urls.py exactly as they demonstrate and I have run the server command:

python manage.py runserver

I get the following error: enter image description here

Since I am new to Django, I do not know what is going on. Please help.

8 Answers

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.

Related