使用一次后,如何删除Django中的会话密钥? [英] How do I delete a session key in Django after it is used once?

查看:142
本文介绍了使用一次后,如何删除Django中的会话密钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个意见。



view1通过会话密钥将错误消息传递给view2。



在view2呈现后,如何删除该键?我只需要一次:从view1重定向到view2。刷新我的网页后,我不需要显示该消息。我不认为python将继续执行一旦达到返回



我正在考虑设置到期时间戳但是我需要确保它存在至少10-20秒,如果应用程序真的这么长时间加载(我们用Django做一些服务器的东西)?所以时间不是很有希望。



谢谢。

解决方案

你可以像任何其他字典一样从会话中删除密钥。

  del request.session ['你的密钥'] 

根据您的一些设置,您可能需要将会话标记为修改以保存。

  request.session.modified = True 


I have two views.

view1 passes an error message to view2 through a session key.

How do I delete the key after view2 is rendered? I only need it for once: redirect from view1 to view2. I dont need that message to show up after refreshing my webpage. I don't think python will continue to execute once it reaches return

I was thinking about setting an expiration timestamp but I need to ensure that it exists for at least 10-20 seconds, if the application really does that long to load (we do some server stuff with Django)? So time is not that promising.

Thanks.

解决方案

You can delete the key from the session like any other dictionary.

del request.session['your key']

You may need to mark the session as modified for it to save, depending on some of your settings.

request.session.modified = True

这篇关于使用一次后,如何删除Django中的会话密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆