Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: how to show results on a web page?

Tags:

python

Most likely it's a dumb question for those who knows the answer, but I'm a beginner, and here it goes:

I have a Python script which I run in a command-line with some parameter, and it prints me some results. Let's say results are some HTML code.

I never done any Python programming for web, and couldn't figure it out... I need to have a page (OK, I know how to upload files to a server, Apache is running, Python is installed on the server...) with an edit field, which will accept that parameter, and Submit button, and I need it to "print" the results on a web page after the user submitted a proper parameter, or show any output that in a command-line situation are printed.

I've read Dive Into Python's chapters about "HTML Processing" and "HTTP Web Services", but they do not describe what I'm looking for.

If the answer isn't short, I would very much appreciate links to the more relevant stuff to read or maybe the key words to google for it.

like image 276
user63503 Avatar asked Oct 07 '09 20:10

user63503


2 Answers

Sounds like you just need to enable CGI on apache, which pretty much will redirect your output to the webserver output.

Python does have CGI library you may take a look at it.

Here's an essay by Guido ( a bit dated )

And an interactive instruction that looks promising.

p.s.

Perhaps you may also want to see Google's offering for this Google app engine ( it may not be what you want though )

like image 140
OscarRyz Avatar answered Oct 05 '22 12:10

OscarRyz


For such a simple task, you probably don't need more than CGI. Luckily Python has a built-in cgi module which should do what you want.

Or you could look into some of the minimal web frameworks, such as web.py.

like image 37
Daniel Roseman Avatar answered Oct 05 '22 12:10

Daniel Roseman