วันพฤหัสบดีที่ 26 มีนาคม พ.ศ. 2552

python receive http post text stream by turbogears2

ในส่วน ของ web controller ของ turbogear นั้น โดยปกติก็จะรับ เป็น kw อยู่แล้ว คือรับ name:value ตาม format

    @expose('templatename')
    def servicename(self, **kw):
        print 'data key, value :', kw
        return dict(page='templatename')

ในกรณีที่เราต้องการ รับ text stream เช่น client อาจ post xml มาเพื่อ information บางอย่างก็จะต้อง ดึงจาก body แทน code ก็จะเพิ่มประมาณนี้ครับ

import pylons

    @expose('templatename')
    def servicename(self, **kw):
        body = pylons.request.body
        print 'data text stream : %s' % body
        return dict(page='templatename')

ไม่มีความคิดเห็น: