0

I've searched around for a while but I can't find a concise explanation of how to do what I want.

I have a fairly complex program which I'd like to make a simple web interface for.

Ideally there'll be a couple of text fields, "foo" and "bar" on a webpage.

When the user clicks submit, a python script "src/script.py" is run, which has access to the contents of these fields somehow.

I have apache2 and mod_python.

Ivy
  • 3,393
  • 11
  • 33
  • 46
  • http://www.modpython.org/live/current/doc-html/tut-pub.html – dm03514 May 07 '12 at 12:35
  • @dm03514: No, please. `mod_python` is dead, no need to exhume it. If `mod_wsgi` is not available, even plain old CGI is better than `mod_python`. – Helgi May 09 '12 at 01:39

3 Answers3

4

If it is a "fairly complex program" you may want to use a small framework that takes care of grouping the parts in a "standard", i.e. supported and documented, manner. I would look into lightweight Python Web frameworks as Flask and WebApp2. Lightweight in terms of both performance and learning curve.

Here you get a full overview of Python web frameworks.

Joseph Victor Zammit
  • 14,760
  • 10
  • 76
  • 102
0

You'll probably want to look into a web framework such as django or webOb

bigblind
  • 12,539
  • 14
  • 68
  • 123
  • I have, but these are way, way too complicated for what I need to do. – Ivy May 07 '12 at 12:38
  • The problem is, that what these frameworks are abstracting away from you is waay more complex. You really don't want to deal with HTTP requests and responses yourself. With a framework like that, you can simply read the data you received, and send your response back, without having to bother with what headers you receive and send. – bigblind May 07 '12 at 18:46
  • Well, Django might be actually _too_ complex for such a simple task. A microframework like Flask or Bottle will allow to write less boilerplate code. Nevertheless, _some_ kind of a framework is a must. No need to reinvent the wheel. – Helgi May 09 '12 at 01:43
0

Here is how it works:

  1. user requestes a web page (a URL like http://127.0.0.1/start.html)

  2. you have to serve the page to the user (either via a standalone webserver like apache or via some python lib like http.server, BaseHTTPServer, flask, cherrypy, ...)

  3. user fills some values in some html form on your page (learn about html forms) when he hits submit another url is requested like http://127.0.0.1/myfunction.py?foo=1&bar=2

  4. you have to handle the request to that url and extract the parameters from the url, for example via cgi, mod_py and apache or python frameworks like flask, cherrypy, etc.. and than you would execute your code using the parameters and generate a resulting html page and serve it via those tools

If you want to keep it really simple, learn howto use flask and html forms.

snies
  • 3,461
  • 1
  • 22
  • 19