2016-08-07 42 views
1

我一直在使用像下面的觀點,因爲圍繞Django 1.5,從所有的Django版本(包括1.9),像一個魅力工作。由於Django 1.10,我的用戶/會話數據丟失與FBV

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 release notes,但沒有什麼我真的可以指向我的手指。我可以忽略一些東西嗎爲什麼突然的行爲改變?

回答

3

Release Notes

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()解決問題。

0

直接從1.5升級到1.10是一個壞主意。嘗試1.51.61.71.81.91.10

render_to_response文檔

這不是推薦,並有可能在將來被棄用。

+0

當然,我沒有從Django 1.5直接更新到1.10。 2016年運行Django 1.5將是一個非常糟糕的主意。功能在1.9到1.10之間破碎,但實現在〜1.5;我會在我的文章中澄清。 – SaeX