Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webpy: How to serve JSON

Tags:

python

web.py

Is it possible to use webpy to serve JSON? I built my website and I need to serve some information in JSON to interact with the Javascript on some pages.

I try to look for answers in the documentation, but I'm not able to find anything.

Thanks, Giovanni

like image 399
Giovanni Di Milia Avatar asked Aug 18 '10 14:08

Giovanni Di Milia


1 Answers

I wouldn't think you'd have to do any thing overly "special" for web.py to serve JSON.

import web
import json

class index:
    def GET(self):
        pyDict = {'one':1,'two':2}
        web.header('Content-Type', 'application/json')
        return json.dumps(pyDict)
like image 89
Mark Avatar answered Nov 11 '22 11:11

Mark