对于Flask中的Session和SessionInterface该如何使用?有没有可以提供一点实例代码?
比如说初始化session 和sessioninterface的open_session和save_session该怎么样使用?
有没有实例代码?
比如说初始化session 和sessioninterface的open_session和save_session该怎么样使用?
有没有实例代码?
7 条回复 • 2014-06-03 09:39:01 +08:00
|
1
wuxqing 2014 年 6 月 1 日
|
|
2
shinerene OP 恩 我知道这个 但是应该怎么在主代码中使用这个interface和session呢?能说一下实际该怎么应用么
|
|
3
dagger 2014 年 6 月 1 日
初始化之后不用再管SessionInterface了吧,session使用的话,教程里就有啊
http://flask.pocoo.org/docs/quickstart/#sessions |
|
4
shinerene OP @dagger 可是我用help()看了session,Session是不一样的,Session是SecureCookieSession类,而session是定义在global类中的,为localproxy()。这两个我在应用的时候应该用Session吧
|
|
5
dagger 2014 年 6 月 2 日
flask通过特殊手段让一些全局变量来代理当前上下文的相关变量:
http://flask.pocoo.org/docs/appcontext/ http://werkzeug.pocoo.org/docs/local/ 原理细节你可以自己去探究,不过使用的时候你连教程都不相信,那也没办法了。。 |
|
7
dagger 2014 年 6 月 3 日
用起来一样的,flask的模块化设计非常好,默认的session也只不过是SessionMixin、SessionInterface的一个实现罢了(SecureCookieSession、SecureCookieSessionInterface)
|
推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide