django render_to_response 未定义错误

发布于 2024-10-28 23:36:57 字数 1238 浏览 5 评论 0原文

您好,当我尝试制作一个简单的应用程序时,我收到此错误。

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

有什么想法吗?

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?!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

£烟消云散 2024-11-04 23:36:57

您是否尝试导入 render_to_response as from django.shortcuts import render_to_response

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

我爱人 2024-11-04 23:36:57

如果您在 2017 年之后阅读本文,请不要 render_to_response 只是 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."

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."
逆蝶 2024-11-04 23:36:57

from django.shortcuts import render_to_response 已弃用。
使用 django.shortcuts 导入渲染

def renderView(request):
input = "Best Times, render"
return render(request,'mytest/home.html',{'mytime': input})

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})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文