25
这是我的代码:如何设置或在Django得到一个cookie的值
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django import http
from django.http import HttpResponse
def main(request, template_name='index.html'):
HttpResponse.set_cookie('logged_in_status', 'zjm1126')
context ={
'a':a,
'cookie':HttpResponse.get_cookie('logged_in_status'),
}
return render_to_response(template_name, context)
#return http.HttpResponsePermanentRedirect(template_name)
它提出了这个异常:
unbound method set_cookie() must be called with HttpResponse instance as first argument (got str instance instead)
我能做些什么?
+1因为它让我笑:)而且因为他是正确的。 – Scotty 2013-01-16 05:30:57
可以设置登录状态(我一直这么做),只是不要在服务器端代码中使用它。 – Blaze 2013-11-30 01:40:12
你的其他答案在哪里?为什么它不好? – avi 2015-06-03 15:46:07