Hi, I want to send a string to a python function I have written and want to display the return value of that function on a web page. After some initial research, WSGI sounds like the way to go. Preferably, I don't want to use any fancy frameworks. I'm pretty sure some one has done this before. Need some reassurance. Thanks!
+5
A:
You can try Flask, it's a framework, but tiny and 100% WSGI 1.0 compliant.
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run()
Note: Flask sits on top of Werkzeug and may need other libraries like sqlalchemy for DB work or jinja2 for templating.
The MYYN
2010-07-20 22:38:25
It's worth noting that Flask is actually a layer over Werkzeug, which is not quite as tiny, though still small enough to be manageable. It does mean you have about 3-4 implicit dependencies though, not merely Flask. (As someone with similar goals to the OP, I don't consider this to be remotely a problem, compared to things like Turbogears2.)
Peter Hansen
2010-07-21 17:34:30
I added your comment. Thanks.
The MYYN
2010-07-21 17:38:17
+1
A:
You can use cgi...
#!/usr/bin/env python
import cgi
def myMethod(some_parameter):
// do stuff
return something
form = cgi.FieldStorage()
my_passed_in_param = form.getvalue("var_passed_in")
my_output = myMethod(my_passed_in_param)
print "Content-Type: text/html\n"
print my_output
This is just a very simple example. Also, your content-type may be json or plain text... just wanted to show an example.
sberry2A
2010-07-20 22:42:37
`cgi` is in the standard library. This is as standalone as you can get.
Ned Batchelder
2010-07-20 22:46:53
Presumably you have a web server installed? How else are you displaying your webpage?
blockhead
2010-07-20 23:53:13
You don't need a full blown web server to display "Hello World!" in HTML. You could write a quick script in python and import the base http server and execute it on some port.
shoold
2010-07-21 00:17:16
A:
I find it hard to believe that what you are asking for is all you will want in the end. If you want something that will help you include things like flash charts on the page(s) you are creating easily, please also take a look at WHIFF http://whiffdoc.appspot.com -- thanks!
Aaron Watters
2010-08-23 16:29:28