Static file problem using the development server

9 views
Skip to first unread message

Rodney Topor

unread,
Aug 9, 2011, 3:24:20 AM8/9/11
to Django users
I tried using a style sheet served as a static file with the tutorial
project. In settings.py, I defined STATIC_URL = /static/ and
STATICFILES_DIRS = ('/path/to/project/static/',). Then I defined a
base_html template with a line in the HEAD of the form

<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}
style.css" />

and put style.css in directory /static/. Finally, I defined
index.html, detail.html, etc., as given in the tutorial to each extend
base.html.

Everything works perfectly, except that only one template
(detail.html) correctly processes the {{ STATIC_URL }} value to find /
static/style.css. In every other template, {{ STATIC_URL }} evaluates
to the empty string, giving just style.css, which does not exist of
course.

Every template extends the single base template in the same way. So
why does {{ STATIC_URL }} work for some templates and not others?

Rodney

Daniel Roseman

unread,
Aug 9, 2011, 4:21:50 AM8/9/11
to django...@googlegroups.com
Because you need to use a RequestContext to render the template.
--
DR. 

Rodney Topor

unread,
Aug 9, 2011, 4:48:22 AM8/9/11
to Django users
Great. Thank you. I missed one, and this somehow affected others.
(Must try to understand what RequestContext really does one day.)

RT

Daniel Roseman

unread,
Aug 9, 2011, 5:07:53 AM8/9/11
to django...@googlegroups.com
It just runs the context processors, which add various things to the context - including STATIC_URL.
--
DR.
Reply all
Reply to author
Forward
0 new messages