从Django 1.5开始,我就一直在使用类似于下面的视图,这在所有Django版本(包括1.9)中都很有魅力。
def site_info(request):
context = RequestContext(request)
context_dict = {}
context_dict['site_version'] = settings.SITE_VERSION
return render_to_response('site_info.html', context_dict, context)
但是,由于Django 1.10,页面加载,但没有可用的会话/用户数据。用户似乎没有登录。回到CBV的时候,一切都很好。运行Django时会显示Session data corrupted
。
另外,像ë
这样的非ASCII字符现在显示为ë
。
我发现问题出在render_to_response
上。当改为render
时,像下面这样,问题就消失了。
def site_info(request):
context_dict = {}
context_dict['site_version'] = settings.SITE_VERSION
return render(request, 'site_info.html', context_dict)
我读了Django 1.10发行说明,但没有任何东西可以指指点点。我是不是忽略了什么?为什么会有突然的行为改变?
发布于 2016-08-07 11:52:37
来自发行说明
The dictionary and context_instance parameters for the following functions are removed:
- django.shortcuts.render()
- django.shortcuts.render_to_response()
- django.template.loader.render_to_string()
更改为render()
可以解决此问题。
发布于 2016-08-07 12:06:10
https://stackoverflow.com/questions/38817898
复制