Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100909 > unrolled thread

Re: CGI

Started byChris Angelico <rosuav@gmail.com>
First post2015-12-28 03:13 +1100
Last post2015-12-28 03:13 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: CGI Chris Angelico <rosuav@gmail.com> - 2015-12-28 03:13 +1100

#100909 — Re: CGI

FromChris Angelico <rosuav@gmail.com>
Date2015-12-28 03:13 +1100
SubjectRe: CGI
Message-ID<mailman.33.1451233162.11925.python-list@python.org>
On Sat, Dec 26, 2015 at 7:35 AM, Pol Hallen <pythonml@fuckaround.org> wrote:
> Merry Christmas to all :-)
>
> A (newbie) question: I'd like learn about CGI pyhton script to create some
> utility using http://localhost/python_script01.py
>
> Something like that:
>
> #!/usr/bin/python
> print "Content-type: text/html"
> print
> print "<html>"
> print "<center>Hello!</center>"
> print "</html>"
>
> How can I execute a local command (like ls or similar) and show output via
> browser?
>
> I didn't find enough documentation to work with python and CGI :-/
>
> Is python not good language to use it with CGI?
>
> Thanks for help! :)

Hi!

I would recommend picking up one of the Python web frameworks like
Django or Flask. It's usually easier than using CGI.

But either way, the easiest way to run a local command is the subprocess module:

https://docs.python.org/2/library/subprocess.html
https://docs.python.org/3/library/subprocess.html

I've provided two links because, unless you have a really good reason
for using Python 2, it'd be well worth using Python 3 instead. There
are lots of neat new features in the 3.x line, so it'll be best to
start on 3.x rather than migrating later. The current release is 3.5,
and new releases keep coming out. :)

ChrisA

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web