static files

21 views
Skip to first unread message

Kai Kobschätzki

unread,
Feb 3, 2020, 8:44:44 AM2/3/20
to django...@googlegroups.com
Hi,

I want to embedding css- and js-files for seperate templates.

I have an django-project with project/static/css/base.css. In the base.html

<snip>

    <!DOCTYPE html>
    <html>
    {% load static %}

</snap>

and in the base.css

<snip>


header {
  background-color: #F8F8F8;
}

</snap>

In my settings.py

<snip>


STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static")
]


STATIC_URL = '/static/'
</snap>

It does what it should do. Changing the base.css-file is displaying. Fine.

Now I extend an app with the directories project/app/static/css and
project/app/static/js and in the subdirectory css I put a app.css in it
and for testing I write there

<snip>

header {
  background-color: #888888;
}

</snap>

In the html-template I write:

<snip>

{% extends 'base.html' %}
{% block content %}
{{ form.media }}
{% load crispy_forms_tags %}
{% load static %}
<script src="{% static 'app/js/app.js' %}"></script>
<link rel="stylesheet" type="text/css" href="{% static 'app/css/app.css'
%}">

</snap>

It doesn't work. :(

My understanding was that django work first the general.css (here
base.css) and the app-specific-css-files so in this case the
background-color will be overwritten. Is this correct?

Anybody know where are my mistakes?

Thanks and Greetings

bengoshi




Murilo A. Gigliotti

unread,
Feb 3, 2020, 9:11:59 AM2/3/20
to django...@googlegroups.com

Hello Bengoshi

 

Try in this way:

 

# Static files (CSS, JavaScript, Images)

# https://docs.djangoproject.com/en/2.2/howto/static-files/

STATIC_URL = '/static/'

#STATIC_ROOT = os.path.join(BASE_DIR, "static")

STATICFILES_DIRS = [

    os.path.join(BASE_DIR, "static"),

    'staticfiles/painel/static',

    'app_catalogo/templates/static/'

]

 

Regards,

Murilo Gigliotti

+55 11 95272-8600

 

-----Mensagem original-----
De: django...@googlegroups.com [mailto:django...@googlegroups.com] Em nome de Kai Kobschätzki
Enviada em: segunda-feira, 3 de fevereiro de 2020 10:44
Para: django...@googlegroups.com
Assunto: static files

--

You received this message because you are subscribed to the Google Groups "Django users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9dbf7d0a-9360-2418-b801-ac13f56b77ad%40gmail.com.

Reply all
Reply to author
Forward
0 new messages