[Django]-How to extend to 'base.html' template styles in Django

2πŸ‘

You have to call the CSS files within the base.html, so when you extend the base.hml in your other pages, the CSS will be called.

For me, I usually do this:

I have Head.html I call all Javascripts and CSS files I am using in the website inside it like this:

for CSS:

<link rel="stylesheet" type="text/css" href="/static/styles/example.css"/>

for javascript:

<script type="text/javascript" src="/static/js/example.js"></script>

then, in each page in the website, after the title tag I include this Head.html like this:

{% include "Head.html" %}

When you do this in every page, the CSS and javascripts files will be seen in all the pages and callable.

Also, the main urls.py file should be like this: β€œthe answer is from hereβ€œ

urlpatterns = [ # ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
πŸ‘€The Maestro

0πŸ‘

On top of your html file add this:

{% extends "base.html" %}
πŸ‘€arrt_

0πŸ‘

It should work, maybe the css path is wrong, or try to delete your {%block style_base%}

πŸ‘€Lemayzeur

Leave a comment