views:

65

answers:

1

The following is the result of CherryPy and css pathing problems I have recently posted, both of which have been answered, but another problem has arisen.

I have a html page which I preview in a browser (via. editor/IDE) and which calls a css file from a css folder in parallel with my application folder (containing main.py and My.html file). For this I use relative pathing in the html header...

 <link rel="stylesheet" href="..\css\commoncss.css" type="text/css">

All good so far. However, when I run Main.py, the css file cannot be found, and the page looks a mess :-( The CP configuration file includes the following line...

tools.staticdir.root = "my\app\folder"  # contains Main.py and My.html

but no other staticdir declarations because CP should be looking for ..\css\commoncss.css relative to the static root folder (am I right?)

I could have my CSS folder as a top-level folder (then I could use href="/css/commoncss" and declare /css as a staticdir), but that's ugly. Alternatively the CSS folder could be a subfolder of the app folder, but I really need the freedom to be able to put the .css file(s) in a different path if possible (could be common to more than one app.).

I really would like to crack this problem, because otherwise it means the html designer cannot use the same template as the Python programmer without changing the href directive.

Any help would be appreciated.

Alan

+1  A: 

but no other staticdir declarations because CP should be looking for ..\css\commoncss.css relative to the static root folder (am I right?)

You can't reach into your physical file directory (static dir) via URLs, nor should you want to.

Cherrypy is looking for the css file relative to your HTML file in the URL hierarchy. If your HTML file is at root, then this won't work. If it's at, say: /stuff/blarg.html, then it would go down to the root and look for the css folder.

I think it's easier to just give an absolute path, because it's reasonable to stipulate that the css directory be in a known location: "/css/commoncss.css"

Ryan Ginstrom
Thanks Ryan - looks like I'll have to forego the convenience of previewing the html directly in a browser. A small price to pay, but a nuisance nevertheless. Regards.
Alan Harris-Reid