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

Итак, совершенно новый для 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, если это имеет значение.

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

Related Posts

  • How to move JavaScript string containing HTML code to it’s own file
  • Proper Way to Deploy Django/Static Files on Heroku
  • Convert Model.Objects.all() to JSON in python using django
  • GenericForeignKey gets wrong id when used with model with UUIDField
  • Is There a Good Way to Forbid Templates Accessing Related Managers Through Model Instances
  • can’t connect details.html to index.html in django
  • Django Rest Framework Serializer charfield not updating when source is given
  • os.getcwd() vs os.path.abspath(os.path.dirname(__file__))
  • Regex exclude .html from string
  • ValidationError doesn’t get printed in my web
  • Overriding django admin get_queryset method
  • how to use array in django
  • Django generate pdf from a template with xhtml2pdf
  • regular expression with special chars
  • Django — REMOTE_HOST empty answer

Other Popular Tags

dataframe

  • R: extract substring with capital letters from string
  • How to identify columns by pattern and convert it to datetime using R?
  • How to convert epoch/unix time in Julia dataframe?
  • Mutate based on two conditions in R dataframe
  • Group by two column and summarize multiple columns
  • Doing calculations between columns of different dataframe where something like a for loop is included using Scala
  • How to create a dot plot from multiple columns in one plot?
  • Row-wise multiplication of selected columns with dplyr
  • Append/Union multiple dataframes in Scala
  • Add rows until today’s date in R

django

  • Firebase Authentication and Django/Djangae
  • Django ‘str’ object has no attribute ‘values’ in rest_framework
  • Dependency installation for Python (Django) project
  • Django error: could not parse the remainder: ‘: «Y-m-d»‘ from ‘post.date|date: «Y-m-d»‘
  • django model field: Why default value not working?
  • Django — accessing foreign key’s Manager from django templates
  • Django Query to get count of all distinct values for particular column
  • Django get() missing 1 required positional argument: ‘header’
  • Argument of type ‘NoneType’ is not iterable with ModelForm
  • Can I access attributes of the first object in a list in Django templates?

numpy

pandas

python

Итак, совершенно новый для 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, если это имеет значение.

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

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.

Answer link : https://codehunter.cc/a/django/django-tutorial-name-httpresponse-is-not-defined

Понравилась статья? Поделить с друзьями:
  • Nabco автоматические двери ошибки
  • N700e ошибка e20
  • N700e ошибка e17
  • N6eak7du ошибка на опель
  • N5i ошибка eberspacher