Skip to main content

Django-Cookiebanner

Installation

pip install django-cookiebanner

Usage

  • Add cookiebanner to your INSTALLED_APPS

  • in your settings (settings.py) specify the different Cookie Groups:

from django.utils.translation import gettext_lazy as _

COOKIEBANNER = {
    "title": _("Cookie settings"),
    "header_text": _("We are using cookies on this website. A few are essential, others are not."),
    "footer_text": _("Please accept our cookies"),
    "footer_links": [
        {"title": _("Imprint"), "href": "/imprint"},
        {"title": _("Privacy"), "href": "/privacy"},
    ],
    "groups": [
        {
            "id": "essential",
            "name": _("Essential"),
            "description": _("Essential cookies allow this page to work."),
            "cookies": [
                {
                    "pattern": "cookiebanner",
                    "description": _("Meta cookie for the cookies that are set."),
                },
                {
                    "pattern": "csrftoken",
                    "description": _("This cookie prevents Cross-Site-Request-Forgery attacks."),
                },
                {
                    "pattern": "sessionid",
                    "description": _("This cookie is necessary to allow logging in, for example."),
                },
            ],
        },
        {
            "id": "analytics",
            "name": _("Analytics"),
            "optional": True,
            "cookies": [
                {
                    "pattern": "_pk_.*",
                    "description": _("Matomo cookie for website analysis."),
                },
            ],
        },
    ],
}
  • In your base template add the banner and the conditionals:
{% load cookiebanner %}
...
<body>
{% cookiebanner_modal 'vanilla' %}
...

<button onclick="document.querySelector('#cookiebannerModal').classList.remove('hidden')">change cookie preferences</button>

{% cookie_accepted 'analytics' as cookie_analytics %}
{% if cookie_analytics %}
<script>... javascript for matomo ...</script>
{% endif %}
</body>

Custom Template

You can create a custom template and use that instead of the default one.

  • Create a folder cookiebanner/ and a file in one of your templates/-folders, e.g.: templates/cookiebanner/mytemplate.html
  • Use {% cookiebanner_modal 'mytemplate' %}

Metadata

Release files for django-cookiebanner 0.2.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-cookiebanner 0.2.8
File Size Uploaded
django_cookiebanner-0.2.8.tar.gz 19.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-cookiebanner 0.2.8
File Interpreter ABI Platform
django_cookiebanner-0.2.8-py3-none-any.whl Python 3 none any Details

Total release size: 41.4 kB

Release files / django_cookiebanner-0.2.8.tar.gz

Download URL django_cookiebanner-0.2.8.tar.gz
Size 19.7 kB
Tags Source
SHA-256 checksum
How to use checksums
fe2ba06f5199aa88aa37c5f615a9da66db7a8325990535db67ac315d27f5a339
BLAKE2b-256 checksum
How to use checksums
087531d0e47b632dbe52fa4f1c94de1c6b1e20fb04e7bcab8b4436cd97c7095a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.2 CPython/3.11.2 Linux/6.2.0-20-generic

Release files / django_cookiebanner-0.2.8-py3-none-any.whl

Download URL django_cookiebanner-0.2.8-py3-none-any.whl
Size 21.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a4f949825f9fd047e0e177a964c49d51bfbc0f0279e9ce0968bc189737a3795
BLAKE2b-256 checksum
How to use checksums
8757ff745985fd68e97356f3b978d5b38365ca665f034a326e84023f2877c812
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.2 CPython/3.11.2 Linux/6.2.0-20-generic

Release history Release notifications | RSS feed

This release

0.2.8 This release

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page