trying to create simple py script

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

trying to create simple py script

Smaran Harihar
Hi Guys,

I am trying to create a simple cgi-script to receive a Ajax
call, manipulate the string received and send it back as JSON.
Most of the people I have spoken to, seemed to be against using the cgi
script, but most of the documentation and tutorials seem to point to cgi
for AJAX calls. They said, it makes more sense to use django or bottle
which are python web framework.

So I am confused and wanted some guidance as to which should I chose?
Should I go with cgi or django/bottle?

--
Thanks & Regards
Smaran Harihar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120809/08fd14b2/attachment.html>

Reply | Threaded
Open this post in threaded view
|

trying to create simple py script

Lutz Horn-4
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


Reply | Threaded
Open this post in threaded view
|

trying to create simple py script

Ifthikhan Nazeem
I have been using Flask for a while and it's been a positive experience so
far. It's simplicity helps you to get things done faster.


On Fri, Aug 10, 2012 at 8:35 AM, Lutz Horn <lutz.horn at fastmail.fm> wrote:

> 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
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120810/4394c116/attachment.html>

Reply | Threaded
Open this post in threaded view
|

trying to create simple py script

Dan Stromberg-2
In reply to this post by Smaran Harihar
CGI's old stuff.  Sure it's easy to find doc about it - it's been around
longer.

I'd recommend either CherryPy or Bottle - because these are the two (that I
know of) that support Python 3 today.

Here's a nice comparison of Python REST frameworks:

http://www.youtube.com/watch?v=AYjPIMe0BhA

I'm using CherryPy on Python 2.7 with the ruby-on-rails-like "Routes"
dispatcher.

Bottle does sound pretty nice.

On Thu, Aug 9, 2012 at 9:52 PM, Smaran Harihar <smaran.harihar at gmail.com>wrote:

> Hi Guys,
>
> I am trying to create a simple cgi-script to receive a Ajax
> call, manipulate the string received and send it back as JSON.
> Most of the people I have spoken to, seemed to be against using the cgi
> script, but most of the documentation and tutorials seem to point to cgi
> for AJAX calls. They said, it makes more sense to use django or bottle
> which are python web framework.
>
> So I am confused and wanted some guidance as to which should I chose?
> Should I go with cgi or django/bottle?
>
> --
> Thanks & Regards
> Smaran Harihar
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120810/0bb282d1/attachment.html>

Reply | Threaded
Open this post in threaded view
|

trying to create simple py script

Smaran Harihar
In reply to this post by Lutz Horn-4
Sorry forgot to update. I did change the port to 8000 and now server is
running but I am getting a 404 page.

http://128.196.142.94:8000/bottle/hello.py

I have the server up right now you can see.

Thanks,
Smaran

On Fri, Aug 10, 2012 at 11:35 AM, Smaran Harihar
<smaran.harihar at gmail.com>wrote:

> Hi Lutz,
>
> Sorry forgot to update. I did change the port to 8000 and now server is
> running but I am getting a 404 page.
>
> http://128.196.142.94:8000/bottle/hello.py
>
> I have the server up right now you can see.
>
> Thanks,
> Smaran
>
>
> On Fri, Aug 10, 2012 at 11:28 AM, Lutz Horn <lutz.horn at fastmail.fm> wrote:
>
>> Hi,
>>
>> Am 10.08.2012 um 19:10 schrieb Smaran Harihar:
>> > python hello.py but I got this traceback error.
>>
>> Use a different port in this line:
>>
>> > run(host='localhost', port=8080)
>>
>> For example 8090 or 8081 or ?
>>
>> Lutz
>
>
>
>
> --
> Thanks & Regards
> Smaran Harihar
>
>


--
Thanks & Regards
Smaran Harihar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120810/522dcba7/attachment.html>