On Topic/OT- templates, static

Apologies in advance for the somewhat off topic but this is a smart group. Working a project with twitter bootstrap and can render the templates but no matter what I try, css, img, js components aren't accessed. Using django-annoying and Kenneth's 'root' code in base.py to relative reference the paths. Both templates dir and static dir have the code root("templates") and root("static") respectively. TIA, V.

Sorry You must be a logged in, registered user to answer a question.

Answers

Kenneth, thanks very much for the clarification on the various URLs and DIRs. It makes much more sense now. Does it really matter if the site wide static files (css, img, js) are down at the app level if the URLS are properly coded? In my case this is a simple informational site and somehow I've placed my files a directory down. I.E. projectname/appname/static/css...etc. Asking for general info purposes in case others find themselves in a similar situation. i realize this is incorrect for a multi-app project.

Have to review my code and I'll be back with further observations.

First thing to check is that both TEMPLATE_DIRS and STATICFILES_DIRS are proper tuples in your settings. They should look like:

STATICFILES_DIRS = (
    root("assets"),
)

Note the comma after the call to root().

Secondly, check that their paths are what you expect. In your Django shell (python manage.py shell), import settings (from django.conf import settings) and check that, say STATIC_ROOT is where you expect it to be (getattr(settings, "STATIC_ROOT")).

You should not need django-annoying, btw.

I'm asking the question because I still can't wrap my head around the media, static dirs & urls code layout.

Somehow got it working, made my life easier by defaulting to external refs for jquery, bootstrap, etc. And {{STATIC_URL}} is required for bootstrap templates in this application.
Vincent C Fulco on
Now I am really confused, all the paths seem correct using the shell exercise above, templates render but static assets do not. Do I have to collect static files first before they render? The docs would suggest local server does that auto-magically.
Vincent C Fulco on
Example: <link href="{{ STATIC_URL }}bootstrap.css" rel="stylesheet" type="text/css" /> I've tried with both as numerous sources online have reflected but I think w/o is the correct way to go. TIA
Vincent C Fulco on
Following up, if I am rendering an .html from project/templates folder and using css/js/img from project/static, does the .html page need static URLs as in the following or not?
Vincent C Fulco on
`MEDIA_ROOT` and `MEDIA_URL` are for the locations, on the filesystem and through the web server respectively, for user-uploaded files. `STATIC_ROOT` and `STATIC_URL` are for your site's site-wide design assets. `STATICFILES_DIRS` is a tuple of locations on the filesystem that Django should look for design assets.
kennethlove (Staff) on