[nSLUG] Python and HTML
frank.geitzler at ns.sympatico.ca
Fri Jan 9 11:35:46 AST 2015
On Fri, 2015-01-09 at 03:16 -0400, Mike Spencer wrote:
> I think I wasn't paying attention, Fran, so I'm unclear on just what
> you're doing.
Mike, I am a newbie to Python, and have been working my way through a
book called Head First Python, by Paul Barry, from O'Reilly books.
After a few introductory chapters introducing a new user to Python, and
to the IDLE integrated development environment (IDE), chapters 5 through
7 introduce a hypothetical application designed to help a
track-and-field coach keep track of his athletes' running speeds over a
600m run. It starts out with individual csv (Comma-Separated Variable)
files for each athlete, with each string containing a list of times
(irregularly recorded, with different separators between minutes and
seconds, which have to be 'sanitized' from a format such as
'2-34,3:21,2.34,2.45...' to a more standard (and sorted) python list
format such as ['2-34', '2-34', '2-45', '3-21', ...] and eventually in
chapter 7 into HTML pages which can be shared with team members and
others over the internet in a 'webapp'. Neither Apache nor any other
production server is mentioned. The book introduces YATE ('Yet Another
Template Engine'), to impliment CGI ( the 'Common Gateway Interface'),
and page 235 states 'Here are the five lines of code needed to build a
web server in Python:
from http.server import HTTPServer, CGIHTTPRequeseteHandler
port = 8080
httpd = HTTPServer(('', port), CGIHTTPRequeseteHandler)
print("Starting simple_httpd on port: " + str(httpd.server_port)
I sent more details to the nSLUG thread and to Byron yesterday, but in
case you missed them I will forward a copy of that message to you
off-thread. This is my first cgi script, and the first step,
'index.html' does get to the local server and is displayed, but is
unable to find the files in the cgi-bin folder. I can forward the
messages generated by the app. if you think it would help.
> You're trying to have an httpd server run cgi-bin scripts, written in
> Python, on localhost, right?
> Are you using Apache as the server? Or another HTTPD server? Do you
> have *any* cgi-bin scripts that work as expected with this server?
> I'm not even an accomplished novice, let alone a wizard, but I
> routinely use several cgi-bin scripts (in Perl, not Python) on my
> machine that work fine almost all the time . That's with the
> Apache server that came with my Slackware 11.0 distro.
> So I'm not clear on whther your problem lies with the Python scripts
> you're creating or with the server configuration that is serving the
> script text as a doc instead of executing it.
> With Apache, there are config details designating which directories
> contain cgi-bin scripts. If your server isn't told that a particular
> dir contains files *intended* to be executed, then I would infer that
> it might not execute them even if they were rwxr-xr-x and properly
> formated with #!/path/to/python top line.
> Sorry to natter on if you've already addressed that point and I
> muddled past it.
> - Mike
>  The only recurring error I see in one cgi-bin script may be due to
> my coding or due to data from the net not arriving in the form
> expected so that my Perl regex stuff fails. Dunno, haven't run it
> down. Doesn't happen often. May be a Heisenbug.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the nSLUG