Ads 468x60px

Labels

Friday, May 4, 2012

Using Python and jQuery

Python has a solid set tools to power web applications. The necessary knowledge lies in passing variables between python and jquery, however this can be hard to figure out. Here is a simple tutorial on how to send information between python and jquery to make python-powered web applications. 1. Write the HTML
Python-jQuery Example


Python-jQuery Example

2. Write the jQuery Script

3. Write the python script
#!/usr/bin/python

import cgi, cgitb 
cgitb.enable()  # for troubleshooting

#the cgi library gets vars from html
form = cgi.FieldStorage()
jquery_input = form.getvalue("stuff_for_python", "nothing sent")

#the next 2 'print' statements are important for web
print "Content-type: text/html"
print

#this is the actual output
print jquery_input

Note: Name the python script test.py. If you are testing this on an OSX, place the python script in /Library/Webserver/CGI-Executables/ (this is the cgi-bin).

0 comments:

Post a Comment

 

Sample text

Sample Text

Sample Text