[Answer]-How to link a main.css to all Django templates?

1πŸ‘

βœ…

I would use a base template containing all your common stuff (JQuery, main.css).

So, you will have a template called base.html will all the basic stuff and placeholders for specific pages content:

<html>
<head>
    <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}/css/main.css">
    {% block additional_header %}
    {% endblock %}
</head>
<body>
    {% block content %}
    {% endblock %}
</body>
</html>

Then, your actual page will be a template with something like this:

{% extends 'base.html' %}
{% block content %}
This is specific content for your page
{% endblock %}

Checkout Django’s official documentation. Look for the section titled Template Inheritance.

Leave a comment