您的位置:首页 > 编程语言 > Python开发

python web with bottle and session (beaker)

2013-12-02 21:58 495 查看
python web with bottle and session (beaker)
http://icodesnip.com/snippet/python/python-web-with-bottle-and-session-beaker     ?
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
       
    #!/usr/bin/python
    # -*- coding: utf-8 -*-
    import bottle as web
    from beaker.middleware import SessionMiddleware
    
    @web.route('/')
    def index():
        session=web.request.environ["beaker.session"]
        if "cpt" in session:
            session["cpt"]+=1
        else:
            session["cpt"]=1
        return "cpt:"+str(session["cpt"])
    
    if __name__=="__main__":
    
        session_opts = {
            "session.type": "file",
            'session.cookie_expires': True,
            'session.auto': True,
            'session.data_dir': "cache",
        }
    
        app = web.default_app()
        
        app = SessionMiddleware(app, session_opts)
    
        web.run(app=app,reloader=True)
    Comments
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: