[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Python CGI script and CSS style sheet

epsilon

1/23/2008 3:15:00 PM

All:

I'm working with a Python CGI script that I am trying to use with an
external CSS (Cascading Style Sheet) and it is not reading it from the
web server. The script runs fine minus the CSS formatting. Does
anyone know if this will work within a Python CGI? It seems that line
18 is not being read properly. One more thing. I tested this style
sheet with pure html code (no python script) and everything works
great.

Listed below is a modified example.

++++++++++

1 #!/usr/bin/python
2
3 import cgi
4
5 print "Content-type: text/html\n"
6 tag_form = cgi.FieldStorage()
7
8 head_open_close = """
9 <head>
10 <meta http-equiv="content-type" content="text/html;
charset=UTF-8">
11 <title>Tag Sheet</title>
12 <link rel="stylesheet" type="text/css" href="central.css">
13 </head>"""
14
15 body_open = """
16 <body>
17 <!-- tag page -->
18 <table class="tag-sheet">
19 <tbody>"""
20

Thank you,
Christopher
2 Answers

Tim Chase

1/23/2008 4:15:00 PM

0

> I'm working with a Python CGI script that I am trying to use with an
> external CSS (Cascading Style Sheet) and it is not reading it from the
> web server. The script runs fine minus the CSS formatting. Does
> anyone know if this will work within a Python CGI? It seems that line
> 18 is not being read properly. One more thing. I tested this style
> sheet with pure html code (no python script) and everything works
> great.
>
> Listed below is a modified example.
>
> ++++++++++
>
> 1 #!/usr/bin/python
> 2
> 3 import cgi
> 4
> 5 print "Content-type: text/html\n"

The answer is "it depends". Mostly on the configuration of your
web-server. Assuming you're serving out of a cgi-bin/ directory,
you'd be referencing

http://example.com/cgi-...

If your webserver (apache, lighttpd, whatever) has been
configured for this directory to return contents of
non-executable items, your above code will reference

http://example.com/cgi-bin/c...

and so you may be able to just drop the CSS file in that directory.

However, I'm fairly certain that Apache can be (and often is)
configured to mark folders like this as "execute only, no
file-reading". If so, you'll likely get some sort of Denied
message back if you fetch the CSS file via HTTP.

A better way might be to reference the CSS file as
"/media/central.css"

12 <link rel="stylesheet" type="text/css"
href="/media/central.css" />

and then put it in a media folder which doesn't have the
execute-only/no-read permission set.

Another (less attractive) alternative is to have your CGI sniff
the incoming request, so you can have both

http://example.com/cgi-...
http://example.com/cgi-...?file=css

using the 'file' GET parameter to return the CSS file instead of
your content. I'd consider this ugly unless deploy-anywhere is
needed, in which case it's not so bad because the deployment is
just the one .py file (and optionally an external CSS file that
it reads and dumps).

-tkc





epsilon

1/23/2008 4:22:00 PM

0

Tim,

Thanks for the information and I'll work with you suggestions. Also,
I will let you know what I find.

Thanks again,
Christopher


Tim Chase wrote:
> > I'm working with a Python CGI script that I am trying to use with an
> > external CSS (Cascading Style Sheet) and it is not reading it from the
> > web server. The script runs fine minus the CSS formatting. Does
> > anyone know if this will work within a Python CGI? It seems that line
> > 18 is not being read properly. One more thing. I tested this style
> > sheet with pure html code (no python script) and everything works
> > great.
> >
> > Listed below is a modified example.
> >
> > ++++++++++
> >
> > 1 #!/usr/bin/python
> > 2
> > 3 import cgi
> > 4
> > 5 print "Content-type: text/html\n"
>
> The answer is "it depends". Mostly on the configuration of your
> web-server. Assuming you're serving out of a cgi-bin/ directory,
> you'd be referencing
>
> http://example.com/cgi-...
>
> If your webserver (apache, lighttpd, whatever) has been
> configured for this directory to return contents of
> non-executable items, your above code will reference
>
> http://example.com/cgi-bin/c...
>
> and so you may be able to just drop the CSS file in that directory.
>
> However, I'm fairly certain that Apache can be (and often is)
> configured to mark folders like this as "execute only, no
> file-reading". If so, you'll likely get some sort of Denied
> message back if you fetch the CSS file via HTTP.
>
> A better way might be to reference the CSS file as
> "/media/central.css"
>
> 12 <link rel="stylesheet" type="text/css"
> href="/media/central.css" />
>
> and then put it in a media folder which doesn't have the
> execute-only/no-read permission set.
>
> Another (less attractive) alternative is to have your CGI sniff
> the incoming request, so you can have both
>
> http://example.com/cgi-...
> http://example.com/cgi-...?file=css
>
> using the 'file' GET parameter to return the CSS file instead of
> your content. I'd consider this ugly unless deploy-anywhere is
> needed, in which case it's not so bad because the deployment is
> just the one .py file (and optionally an external CSS file that
> it reads and dumps).
>
> -tkc