Rodney Topor wrote:
OK, sorry for the unclear message.

I've now discovered that if I use an embedded CSS file in a template -
<style text/css>h1 { color: red}</style> - then it works correctly.
But if I use an external CSS file in a template - <link
rel="stylesheet" type="text/css" href="site.css"> - then, even if the
style sheet only changes font colors, the effect is that the font
style is changed, the font size is changed, and the background
changes.  Now, perhaps the style sheet is not being found.

Assuming you mean 'unchanged', then it's quite likely. Especially if you haven't configured your web server to bypass django for loading the CSS files.

So, if my project has a directory structure "mysite/templates/app/
template.html", then in which directory should I place the CSS file?

The physical directory the template comes from has absolutely no bearing on the URL structure as far as the web server is concerned. What is important for external media files (which includes the CSS, any javascript files and the image files) is whether the web server knows how to find the files.

I put all my media files into a directory structure under the project directory called 'webroot'. And then use an 'Alias' option in Apache to point http://example.com/site-media/ to the webroot folder. You also need to tell it not to use mod_python or whatever mechanism you're using for django. In the template files I then reference the CSS like:

  <link rel="stylesheet" href="/site-media/css/sitemap.css" />

If you are using the generic views, or are passing an instance of RequestContext into the render_to_response function, and have MEDIA_URL set correctly in your settings.py file, then you can simplify this as:

  <link rel="stylesheet" href="{{MEDIA_URL}}/css/sitemap.css" />

This prompts me to ask a related question: If the mysite project has
two apps, is it better to have a separate templates directory within
each app, or a single template directory within the project with a
subdirectory for each app as suggested above, or a single template
directory containing all templates.  (The last solution seems wrong,
poorly structured.)

I do it both ways. If I think the app might be useful elsewhere or is pretty much self-container, then I will put them into the application directory. If they are specific to the website, or someone else is maintaining the HTML (I'm a programmer, not a artist!) then I'll put them in a top level templates folder.

Regards
Darryl

--

Darryl Ross
Director
AFOYI, "Information Technology Solutions"
p +61 8 7127 1831
f +61 8 8425 9607
e [EMAIL PROTECTED]


Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to