Django在非View的地方,想要开启session,最好先在view中开启

via http://docs.djangoproject.com/en/dev/topics/http/sessions/

在view当中使用session的部分,最好改为


    request.session.set_test_cookie()

    if request.session.test_cookie_worked():
       request.session.delete_test_cookie()
    else:
       return HttpResponse("Please enable cookies and try again.")




否则将可能永远出现Please enable cookies and try again.

你可能感兴趣的:(python,django)