[Tutor] Python, CGI and CSS

Alan Gauld alan.gauld at btinternet.com
Fri Apr 11 01:05:50 CEST 2008

"Alex Krycek" <agent.krycek at gmail.com> wrote

> How do I apply an external stylesheet to the XHTML in a Python
> script?

Python doesn't really do anything with CSS that is handled by the 
All Python can do is insert the correct HTML into the server response
to the browser.

> I tried to include the standard "<link rel='stylesheet'
> type='text/css' href='style1.css' />"" in with the rest of the 
> printed
> XHTML. But that didn't work.

What if anything happened?
And how did you test it?
Did the CSS file actually exist in the location specified?

> I changed the href attribute to "/style1.css",
> then to "../style1.css" and finally to 
> "http://localhost/cgi-bin/style1.css",
> all failed attempts. Just so you know, both sets of permissions for 
> these
> two files have been set to 755. I tried other cgi scripts (still 
> residing in
> the cgi-bin) and they did work. I checked the error log, and this is 
> what
> I'm getting: (2)No such file or directory.

So it says the file doesn't exist. Have you double checked that the
css file is in the same folder as the CGI script? When you say you
tried other CGI scripts and they worked, what does that mean?
That they loaded the same CSS file?

If its only the CSS that isn't working you can presumably save
the web page from the browser as HTML? What does the HTML
look like? Is it what you expected? What path is it specifying?

> When I took both files out of my cgi-bin, as a test, the CSS rules 
> were
> implemented. I'm not sure why it stops working when located in the
> cgi-bin folder.

Ok, You obviously understand that paragraph but to the rest of
us it is wholly ambiguous. When you took which files out of cgi-bin?
In what way did they work? What was different exactly that
constituted "working"? What is the "it" that stops working?
The system the CSS, the CGI script? All of the above?

Sorry, but I need a bit more precision in the description to
understand what tyhe problem is. It might help if you can
include a directory tree listing of the significant files - cgi and 
Also the section of the generated HTML that imports the CSS file.


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list