[nSLUG] Python and HTML
hnassrat at gmail.com
Fri Jan 9 11:49:17 AST 2015
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)
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:
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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the nSLUG