'Django Bootstrap 5 - Custom styling

I am using django-bootstrap5 in a Django project.

According to the docs, for customization, I can add the following to settings.py:

BOOTSTRAP5 = {
    "css_url": {}, # I could add a custom URL here
    "theme_url": "..." # Or I could override the theme here
}

Which seems overkill for only a few customizations. How can I customize something like the primary colour of Bootstrap? Do I have to use Sass/Scss, and if so, how does one do this in Django?



Solution 1:[1]

You can add a custom stylesheet and load it in the header of the site (load_static). In that stylesheet you can overwrite the colors of Bootstrap. These are the colors from Bootstrap 5.0.0-beta2:

:root {
  --bs-blue: #0d6efd;
  --bs-indigo: #6610f2;
  --bs-purple: #6f42c1;
  --bs-pink: #d63384;
  --bs-red: #dc3545;
  --bs-orange: #fd7e14;
  --bs-yellow: #ffc107;
  --bs-green: #198754;
  --bs-teal: #20c997;
  --bs-cyan: #0dcaf0;
  --bs-white: #fff;
  --bs-gray: #6c757d;
  --bs-gray-dark: #343a40;
  --bs-primary: #0d6efd;
  --bs-secondary: #6c757d;
  --bs-success: #198754;
  --bs-info: #0dcaf0;
  --bs-warning: #ffc107;
  --bs-danger: #dc3545;
  --bs-light: #f8f9fa;
  --bs-dark: #212529;
  --bs-font-sans-serif: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  --bs-font-monospace: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --bs-gradient: linear-gradient(180deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0));
}

If your css is loaded after the one from django-bootstrap5 it should work (not tested)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 grisuu