Name httpresponse is not defined django ошибка

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.

asked May 25, 2017 at 16:24

SumNeuron's user avatar

1

from django.http import HttpResponse

in your views file at the top

answered May 25, 2017 at 16:27

Exprator's user avatar

ExpratorExprator

26.8k6 gold badges45 silver badges57 bronze badges

0

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

from django.http import HttpResponse

answered May 25, 2017 at 16:29

khue bui's user avatar

khue buikhue bui

1,3463 gold badges21 silver badges30 bronze badges

0

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.

answered Jun 7, 2017 at 2:18

Claudio Scheuermann's user avatar

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

answered Mar 3, 2018 at 5:27

li bing zhao's user avatar

li bing zhaoli bing zhao

1,37813 silver badges12 bronze badges

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.

answered May 8, 2020 at 16:18

HassanSh__3571619's user avatar

1

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.

TylerH's user avatar

TylerH

20.7k65 gold badges73 silver badges98 bronze badges

answered Oct 28, 2017 at 11:51

Jerzy Drożdż's user avatar

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

answered Aug 9, 2018 at 14:00

Maxime Chevallier's user avatar

1

  1. Check your import statement.
  2. Check your function. I had «HttpsResponse» instead of «HttpResponse»

Good luck.

answered Aug 22, 2019 at 2:58

Freddy's user avatar

FreddyFreddy

1441 silver badge5 bronze badges

1

So brand new to Python, trying to get past this django error:

NameError at /hello/
name 'HttpResponse' is not defined
Request Method:
GET
Request URL:
http://localhost:61892/hello/
Django Version:
1.11.7
Exception Type:
NameError
Exception Value:
name 'HttpResponse' is not defined
Exception Location:
c:usersmblaylocksourcereposmysitemysitemysiteviews.py in hello, line 6
Python Executable:
c:usersmblaylocksourcereposmysitemysiteenvScriptspython.exe
Python Version:
3.6.2
Python Path:
['c:\users\mblaylock\source\repos\mysite\mysite',
 'c:\users\mblaylock\source\repos\mysite\mysite',
 'c:\users\mblaylock\source\repos\mysite\mysite\env\Scripts\python36.zip',
 'C:\Program Files\Python36\DLLs',
 'C:\Program Files\Python36\lib',
 'C:\Program Files\Python36',
 'c:\users\mblaylock\source\repos\mysite\mysite\env',
 'c:\users\mblaylock\source\repos\mysite\mysite\env\lib\site-packages']
Server time:
Mon, 13 Nov 2017 18:09:39 +0000

My code is:

class views(object):

    """description of class"""

    from django.http import HttpResponse

def hello(request):
    return HttpResponse("Hello world")

Using Visual Studio for my IDE on Windows 10, if that matters.

Thanks in advance!

Итак, совершенно новый для Python, пытаясь преодолеть эту ошибку django:

NameError at /hello/
name 'HttpResponse' is not defined
Request Method:
GET
Request URL:
http://localhost:61892/hello/
Django Version:
1.11.7
Exception Type:
NameError
Exception Value:
name 'HttpResponse' is not defined
Exception Location:
c:usersmblaylocksourcereposmysitemysitemysiteviews.py in hello, line 6
Python Executable:
c:usersmblaylocksourcereposmysitemysiteenvScriptspython.exe
Python Version:
3.6.2
Python Path:
['c:\users\mblaylock\source\repos\mysite\mysite',
 'c:\users\mblaylock\source\repos\mysite\mysite',
 'c:\users\mblaylock\source\repos\mysite\mysite\env\Scripts\python36.zip',
 'C:\Program Files\Python36\DLLs',
 'C:\Program Files\Python36\lib',
 'C:\Program Files\Python36',
 'c:\users\mblaylock\source\repos\mysite\mysite\env',
 'c:\users\mblaylock\source\repos\mysite\mysite\env\lib\site-packages']
Server time:
Mon, 13 Nov 2017 18:09:39 +0000

Мой код:

class views(object):

    """description of class"""

    from django.http import HttpResponse

def hello(request):
    return HttpResponse("Hello world")

Использование Visual Studio для моей среды разработки в Windows 10, если это имеет значение.

Заранее спасибо!

  • Py Py
  • Feb 17, 2022

Erorr: name ‘HttpResponse’ is not defined

NameError: name 'HttpResponse' is not defined

Solution: name ‘HttpResponse’ is not defined

# Add the following line to the top of your code
from django.http import HttpResponse

For more information:
Django HttpResponse

Search

Recent Posts

Tags

Solution 1

from django.http import HttpResponse

in your views file at the top

Solution 2

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

from django.http import HttpResponse

Solution 3

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.

Solution 4

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

Comments

  • 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.

  • This just reiterates the accepted answer from 2017.

  • This is a typo that other people probably won’t make. At best it’s perhaps comment material. OP also doesn’t have quotes of either type in their scenario, so this is also at best unrelated to the problem.

  • This just reiterates the accepted answer from 2017 except highlighting that you made a typo. At best it should be a comment about the command being case-sensitive, but that’s a rather generous take.

Recents

Возможно, вам также будет интересно:

  • Mystery game epic games ошибка
  • Mysqli error не выводит ошибку
  • Mysqli error не все ошибки
  • Mysql что такое ошибка 1064
  • Mysql проверка таблиц на ошибки

  • Понравилась статья? Поделить с друзьями:
    0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии