Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #26841 > unrolled thread

Re: trying to create simple py script

Started byLutz Horn <lutz.horn@fastmail.fm>
First post2012-08-10 08:35 +0200
Last post2012-08-10 08:35 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: trying to create simple py script Lutz Horn <lutz.horn@fastmail.fm> - 2012-08-10 08:35 +0200

#26841 — Re: trying to create simple py script

FromLutz Horn <lutz.horn@fastmail.fm>
Date2012-08-10 08:35 +0200
SubjectRe: trying to create simple py script
Message-ID<mailman.3144.1344580529.4697.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web