开发者

Django: check cookies are enabled?

I want to check whether cookies are enabled in Django. I have the following code:

def test_cookies(request):
    request.session.set_test_cookie()
    if request.session.test_cookie_worked():
        print 'cookie worked'
        request.session.delete_test_cookie()
    else:
        print 'cookie failed'
        return HttpResponse("Please enable cookies and try again.")

However, if I check 'Disable Cookies > All Cookies' in Firefox's Web Developer Toolbar, and then try loading the page in Firefox, I get 'cookie worked' in the ou开发者_开发知识库tput. Oh dear.

Is there another way to check whether cookies are enabled?

Thanks!


In one action/url you set a cookie and redirect it to other action/url. In that other action you check if cookie is set.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜