大道藏经格 返回首页   发布资源   友情链接   联系我们
 

Get contextual variables with web.py


A simple way to get contextual variables with web.py
格式:--
大小:--

Using web.ctx makes this possible. First a little architecture: web.ctx is based on the class threadeddict a.k.a. ThreadedDict. This class creates a dictionary-like object that has attributes specific to the thread process id. This is nice because it lets us use a dictionary-like object when many users are accessing the system simultaneously, and the object will only have the data for the given HTTP request (no data is shared so the object is thread-safe).

web.ctx holds variables for each request that contain specific information to each request such as the client environment variable. Assuming you want to determine what the referring page was for a user accessing a page:

Example
class example:
    def GET(self):
        referer = web.ctx.env.get('HTTP_REFERER', 'http://google.com')
        raise web.seeother(referer)
This code uses web.ctx.env to access the HTTP_REFERER environment variable. If there isn't one, it defaults to google.com. Finally, it redirects the user to the page they came from.

web.ctx is also useful because it can be set by a loadhook. Session data, for example, is set each time a request is handled and the data is stored in web.ctx. Since web.ctx is thread-safe, you can use the session data as if it were a regular python object.

本资源由“匿名网友”提交。
浏览本类别全部资源



截拳道之道

李小龙亲笔著作,不可多得的珍贵资料


正宗咏春木人桩法116式

叶问宗师亲自演示,叶准师傅著作


河南正宗心意拳

凶猛凌厉的内家武术


美国海军陆战队近距离格斗手册

彪悍实用的军用格斗技术

Acrobat Reader

用来阅读PDF电子书的阅读器软件。
点这里免费下载

ScarAngle

刀疤天使-优秀的电骡软件。
点这里免费下载

7-Zip

全能压缩解压缩软件,免费开源。
点这里免费下载
 
本站仅保存资源下载链接,不保存文件实体。本站搜藏系出于个人爱好,所有资源均来自搜索引擎和网友提交,如有侵权之处,请联系站长dadaorun#hotmail.com删除。