Question

I'm interested in making a pretty basic Python webapp, literally just a form that takes in some input, calls a Python function on that input, receives results returned from that function, and then uses web development trickery to make them look pretty. I've seen numerous solutions using CherryPy, flask, bottle, web.py, all of which are great, but I haven't seen an example where any of those actually uses Apache. They all seem to be this all-in-one web server framework, which is totally overkill for me and not what I need. I already have Apache running here, so rather than start up a second web server and have to worry about keeping it running, I'd rather just have Apache serve my app along with everything else all day long.

We have the fairly standard http://myserver.com/~user/ setup with public_html dirs in /home/user, but for the life of me I can't figure out how to create a page that calls a Python function that is served up and has the Python code actually execute when browsing to http://myserver.com/~user/. Let's assume for the moment mod_python or even mod_wsgi is setup correctly...what do I need to do on my end? Do I need to call my script via a PHP exec(), which to me defeats the need for mod_python in the first place, or is there a more elegant solution (that actually uses mod_python)?

Was it helpful?

Solution

Your concept of python scripts are totaly wrong. Don't treat them like PHP scripts where you can have

<html>
<?php
echo "<title>Hello World</title>";
?>
</html>

an mod_php will parse it and execute php code to form final html page.

It's better to say that you have python application where mod_python and mod_wsgi provides interface (gateway) for apache to communicate with your application.

I have been asked quite a lot of times if one can write python web application without framework. Of course you can but you have to deal with HTTP meet and bones like headers and respones codes. Look at http://lucumr.pocoo.org/2007/5/21/getting-started-with-wsgi/.

So I'd suggest using framework.

If you don't want to mess with running your application like deamon look at, for example, this page http://flask.pocoo.org/docs/deploying/mod_wsgi/. It shows how to run flask app with apache and mod_wsgi.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top