Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: trying to create simple py script

19 views
Skip to first unread message

Lutz Horn

unread,
Aug 10, 2012, 2:35:26 AM8/10/12
to python-list
Hi Smaran,

Am Do, 9. Aug 2012, um 23:52, schrieb Smaran Harihar:
> I am trying to create a simple cgi-script to receive a Ajax
> call, manipulate the string received and send it back as JSON.

I can recommend bottle. The following example manipulates a JSON request
body and returns it. That is *much* easier than using CGI.

#!/usr/bin/env python

from bottle import request, post, run

@post('/hello')
def index():
if request.headers.get('X-Requested-With') == 'XMLHttpRequest':
body = request.json
body["baz"] = "qux"
return body
else:
return 'This is a normal HTTP Post request.'

run(host='localhost', port=8080)

Lutz
0 new messages