[mod_python] CSS sheets and XML formatting - Maybe apache config?

Graham Dumpleton grahamd at dscpl.com.au
Fri Oct 20 19:29:42 EDT 2006


On 21/10/2006, at 9:03 AM, <ecastro1981-misc at yahoo.com> wrote:

> Hi,
>
> Sorry I am a newbie. I have been testing out the following example  
> from the CSS wikipedia article but I do not get the same output as  
> displayed in wikipedia. As an actual xml file with a css page it  
> works but I think I am doing something wrong with the modpython  
> handlers.
>
> http://en.wikipedia.org/wiki/Cascading_Style_Sheets
>
> my file is test.py
> ===========================
> from mod_python import apache
>
> def say(req, what="NOTHING"):
>     return "I am saying %s" % what
>
> def test4(req):
>     req.content_type = 'text/xml; charset=UTF-8'
>     req.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
>     req.write("<?xml-stylesheet type=\"text/css\" href=\"C:\Program  
> Files\Apache Software Foundation\Apache2.2\htdocs\css.css\"?>")

The href value here is wrong for a few reasons and will not work.  
First is that
href values which refer to a file system directory for a browser to  
lookup must
start with 'file:///'. Second is whether one can even make a browser  
pick up a
local filesystem file by mentioning it in a href like this. Third is  
that your back
slashes are properly escaped properly and it isn't going to be what  
you want.
Try using Python to print the value of your string and you will see  
what I mean.

>     req.write("<schedule>")
>     req.write("<date>Tuesday 20 June</date>")
>     req.write("<programme>")
>     req.write("<starts>6:00</starts>")
>     req.write("<title>News</title>")
>     req.write("With Michael Smith and Fiona Tolstoy.")
>     req.write("Followed by Weather with Malcolm Stott.")
>     req.write("</programme>")
>     req.write("<programme>")
>     req.write("<starts>6:30</starts>")
>     req.write("<title>Regional news update</title>")
>     req.write("Local news for your area.")
>     req.write("</programme>")
>     req.write("<programme>")
>     req.write("<starts>7:00</starts>")
>     req.write("<title>Unlikely suspect</title>")
>     req.write("Whimsical romantic crime drama starring Janet")
>     req.write("Hawthorne and Percy Trumpp.")
>     req.write("</programme>")
>     req.write("</schedule>")
>     return
>
>
> def test5(req):
>     req.content_type = 'text/xml; charset=UTF-8'
>     req.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
>     req.write("<?xml-stylesheet type=\"text/css\" href=\"css.css\"?>")

Is you css.css file in the same directory as your publisher .py  
files? What Apache
configuration have you used to enable the use of mod_python, did you use
SetHandler or AddHandler? If you used SetHandler, then all requests  
go to
mod_python and a static .css file will never be able to be served up.

There could also be issues dependent on which URL you used to access the
resource in the first place as publisher is really sloppy about how  
it deals with
trailing slashes and it is possible to have URLs notionally targeting  
different
levels in the URL hierarchy ending up at the same resource with the  
result
being that relative URLs are broken.

In summary, post the snippet of Apache configuration that you are  
using to
enable use of mod_python.publisher. Also indicate what URL you are using
and where the .css file is located relative to the .py files.

Graham

>     req.write("<schedule>")
>     req.write("<date>Tuesday 20 June</date>")
>     req.write("<programme>")
>     req.write("<starts>6:00</starts>")
>     req.write("<title>News</title>")
>     req.write("With Michael Smith and Fiona Tolstoy.")
>     req.write("Followed by Weather with Malcolm Stott.")
>     req.write("</programme>")
>     req.write("<programme>")
>     req.write("<starts>6:30</starts>")
>     req.write("<title>Regional news update</title>")
>     req.write("Local news for your area.")
>     req.write("</programme>")
>     req.write("<programme>")
>     req.write("<starts>7:00</starts>")
>     req.write("<title>Unlikely suspect</title>")
>     req.write("Whimsical romantic crime drama starring Janet")
>     req.write("Hawthorne and Percy Trumpp.")
>     req.write("</programme>")
>     req.write("</schedule>")
>     return
>
>
> I was hoping a call to test4 or test5 would pickup the css file but  
> nothing happened. Does my apache conf file need something else. I  
> strongly suspect I need to declare some directory in my apache conf  
> file, but I am stuck.
>
> Should I create an xml file and then send it over? Or is does this  
> call for cString?
>
> Any help with this would be appreciated.
>
> Thank You,
> E
>
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python


More information about the Mod_python mailing list