In Django, it is possible to use different Css files in one HTML document ?
I would like to use one css for base.html and another one for page1.html while expanding base.html to page1.html...
For example, base.html :
{% load static %}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="{% static "css/base.css" %}">
</head>
{% block content %}{% endblock%}
</body>
</html>
and page1.html :
{% extends "base.html" %}
{% load static %}
<link rel="stylesheet" href="{% static "css/page1.css" %}">
{% block content %}
code...
{% endblock %}
I don't want to merge the Css files, do I have an another solution ?
You can use as many CSS files as you like, of course.
The best thing to do here is to define a specific block inside your base template's <head>
section for extra CSS, or any other content you might want to put there. So:
{% load static %}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="{% static "css/base.css" %}">
{% block extrahead %}{% endblock %}
</head>
...
Then your child template can be:
{% extends "base.html" %}
{% load static %}
{% block extrahead %}
<link rel="stylesheet" href="{% static "css/page1.css" %}">
{% endblock %}
...
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