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:

Since I am new to Django, I do not know what is going on. Please help.
asked May 25, 2017 at 16:24
![]()
1
from django.http import HttpResponse
in your views file at the top
answered May 25, 2017 at 16:27
ExpratorExprator
26.3k6 gold badges44 silver badges55 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 buikhue bui
1,3363 gold badges21 silver badges29 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
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 zhaoli bing zhao
1,35813 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
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
20.4k62 gold badges75 silver badges96 bronze badges
answered Oct 28, 2017 at 11:51
For me it was because I used singe quotes (‘) instead of double quotes («)
answered Aug 9, 2018 at 14:00
1
- Check your import statement.
- Check your function. I had «HttpsResponse» instead of «HttpResponse»
Good luck.
answered Aug 22, 2019 at 2:58
![]()
FreddyFreddy
1441 silver badge4 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, если это имеет значение.
Заранее спасибо!

Add Answer
|
View In TPC Matrix
Technical Problem Cluster First Answered On
May 29, 2022
Popularity
4/10
Helpfulness
3/10
Contributions From The Grepper Developer Community
Contents
Code Examples
Related Problems
TPC Matrix View Full Screen
make_response is not defined django
Comment
0
Popularity
4/10 Helpfulness
3/10
Language
python
Source: Grepper
Tags: defined
django
python

Contributed on May 29 2022
MitchAloha
613 Answers Avg Quality 7/10
Grepper
Features
Reviews
Code Answers
Search Code Snippets
Plans & Pricing
FAQ
Welcome
Browsers Supported
Grepper Teams
Documentation
Adding a Code Snippet
Viewing & Copying Snippets
Social
Twitter
LinkedIn
Legal
Privacy Policy
Terms
Contact
support@codegrepper.com
Я импортировал эти модули:
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
а затем я пытаюсь вызвать такой класс:
sh = MyClass(request.FILES['img'])
sh.read_image()
но выдает ошибку «NameError: имя ‘запрос’ не определено», но я не понимаю, почему, потому что я импортировал необходимые модули.
2 ответы
Где ты делаешь свой класс? Если вам нужен доступ к request, вы обычно должны находиться внутри представления, например:
def my_view(request):
sh = MyClass(request.FILES['img'])
sh.read_image()
return render_to_response('template.html')
ответ дан 21 авг.
Ни один из этих операторов импорта не использует имя «запрос», поэтому вы не можете импортировать это имя.
В любом случае запрос — это не то, что вы импортируете, это то, что передается каждому представлению. Если ваш код находится за пределами представления, вам необходимо передать ему запрос.
ответ дан 13 мая ’14, 12:05
Не тот ответ, который вы ищете? Просмотрите другие вопросы с метками
django
or задайте свой вопрос.