django render_to_response is not defined error
Asked Answered
E

3

17

Hi I am getting this error, while I tried make a simple app.

NameError at /first/

global name 'render_to_response' is not defined

Request Method:     GET
Request URL:    http://localhost:8000/first/?preview
Django Version:     1.3
Exception Type:     NameError
Exception Value:    

global name 'render_to_response' is not defined

Exception Location:     /home/naveen/django_projects/myproject/first/views.py in index, line 5
Python Executable:  /usr/bin/python
Python Version:     2.6.6
Python Path:    

['/home/naveen/django_projects/myproject',
 '/usr/local/lib/python2.6/dist-packages/pip-0.8.3-py2.6.egg',
 '/usr/local/lib/python2.6/dist-packages',
 '/usr/local/lib/python2.6/dist-packages/django_evolution-0.6.2-py2.6.egg',
 '/usr/lib/python2.6',
 '/usr/lib/python2.6/plat-linux2',
 '/usr/lib/python2.6/lib-tk',
 '/usr/lib/python2.6/lib-old',
 '/usr/lib/python2.6/lib-dynload',
 '/usr/local/lib/python2.6/dist-packages',
 '/usr/lib/python2.6/dist-packages',
 '/usr/lib/python2.6/dist-packages/PIL',
 '/usr/lib/python2.6/dist-packages/gst-0.10',
 '/usr/lib/pymodules/python2.6',
 '/usr/lib/python2.6/dist-packages/gtk-2.0',
 '/usr/lib/pymodules/python2.6/gtk-2.0']

Server time:    Thu, 31 Mar 2011 14:50:32 -0500

any ideas?!

Exclave answered 31/3, 2011 at 19:52 Comment(1)
Could you post some of your view.py code? The obvious answer is that from django.shortcuts import render_to_response is missing.Purloin
F
52

Did you try import render_to_response as from django.shortcuts import render_to_response?

Fresnel answered 31/3, 2011 at 19:54 Comment(1)
Deprecated, see below.Epps
B
11

If you're reading this beyond - 2017 , don't render_to_response just render:

https://docs.djangoproject.com/en/1.11/topics/http/shortcuts/#render-to-response

Source - Django official documentation for version - 1.11 
" render_to_response()¶

render_to_response(template_name, context=None, content_type=None, status=None, using=None)[source]¶

This function preceded the introduction of render() and works similarly except that it doesn’t make the request available in the response. 
It’s not recommended and is likely to be deprecated in the future."
Bellis answered 18/11, 2017 at 8:39 Comment(0)
D
1

from django.shortcuts import render_to_response is deprecated. use django.shortcuts import render

def renderView(request):
input = "Best Times, render"
return render(request,'mytest/home.html',{'mytime': input})
Dostie answered 11/4, 2020 at 7:21 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.