[nSLUG] Python and HTML
frank.geitzler at ns.sympatico.ca
Thu Jan 8 23:35:18 AST 2015
On Thu, 2015-01-08 at 17:50 -0400, Byron Winmill wrote:
> Is the server configured to allow CGI programs in general, as well as
> to allow CGI programs in that particular directory?
Byron, as far as I can tell, there should be no restrictions.
I used IDLE to determine my Python search path:
>>> import sys
[‘/home/frank’, ‘/usr.bin’, ‘/usr/lib/python3.1’,
I stored the code for the server, simple_httpd.py in the
directory /home/frank, together with the other sub-directories and files
The code for the server is:
from http.server import HTTPServer, CGIHTTPRequestHandler
port = 8080
httpd = HTTPServer(('', port), CGIHTTPRequestHandler)
print("Starting simple_httpd on port: " + str(httpd.server_port))
The server is started in a terminal window by changing to the sub-directory "/home/frank" in which it resides, and issuing the following command (where the name of the file is simple_httpd.py):
I then open FireFox and enter "http://localhost:8080/", at which point the form "index.html" is displayed. That form is in the same directory as is the server code, as are
the following files and sub-directories which are also required:
folders; cgi-bin, data, images, templates
files: coach.css, favicon.ico
The code for the entire application can be found as part of the download
for the examples of chapter 7 at:
if you care to dig that deeply into it, or I can send individual files
if desired -I just don't want to fill up this thread too much.
Thanks for your suggestions.
> On Thu, Jan 8, 2015 at 9:52 AM, Frank Geitzler
> <frank.geitzler at ns.sympatico.ca> wrote:
> Has anyone experience with Python generating HTML? I have been
> attempting to learn Python by working my way through a book called
> HeadFirstPython, and Chapter 7 purports to create a HTML application
> with a main form ("webapp/index.html") calling a subsidiary form
> ("webapp/cgi-bin/generate_list.py"), which in turn will call additional
> subsidiary forms or alternatively will return to the main form. The
> main form correctly appears when the simple local server is started and
> the Firefox website is pointed to "http://localhost:8080/". The
> filename "cgi-bin/generate_list.py" is displayed when the mouse hovers
> over the proper selection area, but when that area is selected, rather
> than invoking generate_list.py, gedit is invoked and it attempts to
> display the contemts of that file, but appears unable to locate it. The
> file "cgi-bin/generate_list.py" begins with #! /usr/local/bin/python3
> and has been marked executable with the command "chmod +x
> generate_list.py ".
> Any suggestions would be appreciated.
> nSLUG mailing list
> nSLUG at nslug.ns.ca
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the nSLUG