Why isn't django isn't parsing and replacing the template tags in my css file? -
this snippet settings file
static_url = '/static/' staticfiles_dirs = [ os.path.join(base_dir, 'static'), ] static_root = os.path.join(os.path.dirname(base_dir), 'static_cdn') media_url = '/media/' media_root = os.path.join(os.path.dirname(base_dir), 'media_cdn')
i have folder in base directory titled static within named css blog.css styles reside.
my html file linked css file using:
{% load staticfiles %} <head> <link rel="stylesheet" href="{% static 'css/blog.css' %}"> </head>
media files(pictures) have no problems. command line shows static files being collected static_cdn ,
`/static/css/blog.css http/1.1" 200 39`
while presume means django has no problem locating css file styles aren't showing in project.
finally, block css file, block far:
body: { background: url("{% static 'images/jumbotron.jpg' %}"); }
can please point me in right direction? thank you
putting in css file not work expect.
// /static/css/blog.css body: { background: url("{% static 'images/jumbotron.jpg' %}"); }
to fix specific problem, follow advice in other answers. i'll try explain why current approach not working.
the django template engine doesn't parse css files unless explicitly tells so. templates useful processing html content change 1 request next.
css files total different case. it's better build them once, using stylesheet processor sass or stylus, , serve same css file every visitor.
or can write plain old css hand, better small projects. learning css preprocessing project in itself.
in theory, use django view serve generated css files dynamically on every request, seems waste of processing cycles.
if want use django template tags in css, it's better use inline stylesheets in head of html page. can put styling common pages in css file, , have custom dynamic stuff in head. work.
{% load staticfiles %} <head> <link rel="stylesheet" href="{% static 'css/blog.css' %}"> <style> body: { background: url("{% static 'images/jumbotron.jpg' %}"):} </style> </head>
this used myspace-style pages want give users ability vandalize own pages custom fonts , background images of own choice.
Comments
Post a Comment