There are two things you can do without making your css files into
templates.

1. Always use relative paths in the css.
div.background {
    background: url("../img/background.png")
}

Thats how I did it in the beginning. Unfortunately our css files keeps
moving around, during development they are split into several files
but during deployment most of them are merged into one file which
means the relative path is different during development and
production.

2. Use absolute paths and the base href attribute.
<html file> <base href="http://example.com/subpath/"; />
<css file> div.background {
    background: url("/static/img/background.png")
    background: url("static/img/background.png")
}

This can sometimes cause other problems with relative paths like if
you have a page at "http://example.com/subpath/foo"; and wanted to make
a link to "http://example.com/subpath/foo/bar";. Ordinarily you could
just write <a href="bar">link to foo/bar</> but if you use the base
tag your link will go to "http://example.com/subpath/bar"; instead.
request.route_url always generate the full link.

On Jan 5, 10:24 pm, Thomi Richards <[email protected]> wrote:
> Hi,
>
> I'm working on a pylons project, and we have users trying to host the
> web-app under a non-root path (i.e. host it at '/myapp/' rather than at
> '/'). We've been pretty good about using 'h.url_for' to generate links in
> our jinja2 templates, so most things work as expected. However, our CSS
> file has paths to icons, background images etc. Since these are served as
> static files these paths never get modified.
>
> I'm sure this is a problem lots of people come across - can anyone suggest
> a solution? I can think of two possibilities:
>
> 1) Remove all paths from the css files, and put them in the jinja2
> templates instead - this seems really ugly, and I'd rather not do this.
> 2) Somehow serve the css file as a jinja2 template. It'd be nice if there
> was some way to say ' all requests for a .css file should render the
> requested file with jinja2 and return the result.'
>
> Any ideas?
>
> Cheers,
>
> --
> Thomi Richards

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to