Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load static css into django template

Tags:

python

django

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".
like image 923
okonik Avatar asked Nov 01 '22 06:11

okonik


1 Answers

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" %}.

like image 144
Domen Blenkuš Avatar answered Nov 11 '22 05:11

Domen Blenkuš