Python CGI script and CSS style sheet

E

epsilon

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
 
T

Tim Chase

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-bin/foo.py

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/central.css

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-bin/foo.py
http://example.com/cgi-bin/foo.py?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
 
E

epsilon

Tim,

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

Thanks again,
Christopher
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top