i use this code :
request.session.set_test_cookie()
the all code is :
def main(request, template_name='index.html'):
context ={
'a':a,
'cookie':request.session.set_test_cookie(),
}
return render_to_response(template_name, context)
but it return None ,
what can i do ,
thanks
set_test_cookie()just sets a cookie on the client’s browser, it doesn’t return anything, hence theNoneYou can’t tell if the browser is actually storing that cookie until the next request where you would check if the cookie was successfully set via
test_cookie_worked()— that’s the test: if the browser doesn’t show the cookie you set, it’s not accepting cookies. If it does return the cookie, it’s proof that cookie are being set, and you’d delete it withdelete_test_cookie()Read docs for more info: I’d be copy and pasting the docs at this point 🙂
http://docs.djangoproject.com/en/dev/topics/http/sessions/#setting-test-cookies
Or feel free to ask any questions.