I'm just newbie in django. Just learning. Want to know how to make best loading of css into django template. Work in django-env
with django 1.8
So, how I'm trying
settings.py
STATIC_URL = '/static/'
STATICFILES_DIRS = (
('static', '/home/djangoenv/bin/mysuperapp/static'),
)
my_template
{% load staticfiles %}
<!DOCTYPE>
<html>
<head>
<title>Django</title>
<link rel="stylesheet" type="text/css" href='{% static "/css/foundation.css" %}'>
</head>
<body>
<h1>Django</h1>
</body>
</html>
In this case I have no loaded css and a warning message in Chrome Console:
Resource interpreted as Stylesheet but transferred with MIME type
text/html: "http://127.0.0.1:8000/css/foundation.css".
Remove 'static'
in STATICFILES_DIRS
STATICFILES_DIRS = (
'/home/djangoenv/bin/mysuperapp/static',
)
This static
creates separate namespace, so you would have to call {% static "static/css/foundation.css" %}
.
And use static
templatetag without leading slash: {% static "css/foundation.css" %}
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With