webpy+DBUtils是如何将数据库连接数占满的

webpy中auto_application的cookie共享问题

妙音 posted @ 2013年11月16日 09:27 in webpy , 2972 阅读

在webpy中使用auto_application划分网站的url结构,会发现是个很好用的东西。

使用过程中却发现每个auto_application默认有自己单独的cookie。

范例

#encoding=utf-8
import web
appA = web.auto_application()
appB = web.auto_application()

urls = (
    '/save',   appA,
    '/get',    appB
)

class SaveName(appA.page):
    path = '/?'

    def GET(self):
        web.setcookie("name", "wyq", expires=24 * 60 * 60)
        return web.cookies().get("age")


class GetName(appB.page):
    path = '/?'

    def GET(self):
        return web.cookies().get("name")

app = web.application(urls, globals())

if __name__ == '__main__':
    web.config.debug = True
    app.run()
    #print app.request("/save").data
    #print app.request("/get").data

上面代码,生成两个auto_application appA与appB。

appA处理所有以/save开头的url请求,appB处理所有以/get开头的url请求。

appA = web.auto_application()
appB = web.auto_application()

发送http://0.0.0.0:8080/save请求,将name信息保存在cookie中。

web.setcookie("name", "wyq", expires=24 * 60 * 60)
 
发送http://0.0.0.0:8080/get请求,获取name值。
预想是返回name值,却发现结果为空。什么原因呢?
观察下面从chrome中取到的截图。
/save请求
 
注意上面的Set-Cookie,多了个path=/save/。原来在application中保存cookies时,会设置cookies的path属性。
 
cookie的path属性,用于限制cookie的访问域,只有此域下的请求才能取到此cookie信息。
换句话说只有url以/save/开头的请求才能,取到此cookie的信息。
上面appA属于/save/域下的,appB属于/get/域下的。它们属于不同的域,所以appB访问不到appA中的cookie。
 
如何解决呢?办法就是在设置cookie时添加path="/"的属性,即可解决。
web.setcookie("name", "wyq", expires=24 * 60 * 60, path="/")
 
 
 
Avatar_small
먹튀검증업체 说:
2020年12月27日 17:06

Great knowledge, do anyone mind merely reference back to it 먹튀검증업체

Avatar_small
ryse residences cond 说:
2021年1月07日 15:37

ดูบอลออนไลน์ ดูบอลสด ต้องดูบอลรวย อัพเดทสดใหม่ทุกวัน พร้อมทั้งมี ไฮไลท์บอล โปรแกรมบอล ผลบอล ราคาบอล หรือ ข่าวสารกีฬา และ ข่าวดังข่าวกระแสอีกมากมาย <a href="http://ดูบอลรวย.com/">ดูบอลออนไลน์</a>

Avatar_small
ryse residences cond 说:
2021年1月07日 18:42

Apply Fastag ICICI Bank is a brand name owned by Indian Highways Management Company Ltd. (IHMCL) which carries out electronic tolling and other ancillary projects of National Highway Authorities of India (NHAI). This Radio Frequency Identification Device (RFID) tag is affixed on the windscreen of the vehicle.

Avatar_small
ryse residences cond 说:
2021年1月07日 21:29

The UAN or Unifiedportal.epfindia.gov.in Account Number is an umbrella number for the multiple Employee Provident Fund Numbers or Member IDs allotted to an individual by various employers. The idea is to link these multiple employee PF Number of a person to a single 12-digit Universal Account Number. This means the account number remains unchanged across organizations since it is linked to a particular person.

Avatar_small
ดูหนังโป๊ออนไลน์ 说:
2021年1月07日 22:18

Your post is very helpful to get some effective tips to reduce weight properly. You have shared various nice photos of the same. I would like to thank you for sharing these tips. Surely I will try this at home. Keep updating more simple tips like this.  ดูหนังโป๊ออนไลน์

Avatar_small
ryse residences cond 说:
2021年1月08日 14:46

To avail the Transfer claim or Advance Withdrawal Claim or Permanent Withdrawal Claim facilities, updating KYC is a mandatory requirement. Once the KYC details are submitted by the employees, the employer has to verify and approve the KYC details using the Digital Signature registered on the Employees Provident Fund Establishment Portal i.e Unifiedportal-emp.epfindia.gov.in.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter