[nSLUG] Python and HTML

Hatem Nassrat hnassrat at gmail.com
Fri Jan 9 11:49:17 AST 2015


Hi Frank,

…
On Fri Jan 09 2015 at 11:36:06 AM Frank Geitzler <
frank.geitzler at ns.sympatico.ca> wrote:

>     port = 8080
>     httpd = HTTPServer(('', port), CGIHTTPRequeseteHandler)
>
>     print("Starting simple_httpd on port: " + str(httpd.server_port)
>     httpd.serve_forever()
>

These lines actually start an HTTP Server (like apache, nginx in the sense
that it talks HTTP) that only servers ONE thing, the CGIHTTPRequestHandler
that you created. Basically saying, for this example in your book, you
don't need any server ontop of the script. It will start a server for your
script on port 8080, so if you go to http://localhost:8080 in your browser
you should see the page you built.

To have many scripts in a cgi-bin directory, you will actually have to
delete the lines mentioned above, and instead do something like this:
https://wiki.python.org/moin/CgiScripts

However, this would be ill-advised, since writing cgi scripts is a way of
the past ... way way back. I would advise you to pick up a web framework
... there are simple ones (like bottle <http://bottlepy.org/>) or bigger
ones (like django <https://docs.djangoproject.com/en/1.7/>), of course
there is a million and one web frameworks out there, I just mentioned two
of the ones I like to use.

My advice is once you get a hang of the cgi server as mentioned in your
book you should look at bottle tutorial and you will hopefully see that it
is an easy migration of you code.

Thanks,

-- Hatem
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nslug.ns.ca/pipermail/nslug/attachments/20150109/d6e03ac4/attachment-0001.html>


More information about the nSLUG mailing list