Skip to main content

No project description provided

Project description

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' %}
...


{% 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' %}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-cookiebanner-0.2.6.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

django_cookiebanner-0.2.6-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

File details

Details for the file django-cookiebanner-0.2.6.tar.gz.

File metadata

  • Download URL: django-cookiebanner-0.2.6.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.1 CPython/3.10.4 Linux/5.15.0-48-generic

File hashes

Hashes for django-cookiebanner-0.2.6.tar.gz
Algorithm Hash digest
SHA256 143c5505f764972968a8f651ca259f5a29a0c1f68081aab24b29f0ef1f30fa78
MD5 4665e40225c7c520817bca41d456afc7
BLAKE2b-256 eb3798fe94e0afe34d2eeaaddd0e94aacaf8a31c584be08677268a8595ee0a93

See more details on using hashes here.

Provenance

File details

Details for the file django_cookiebanner-0.2.6-py3-none-any.whl.

File metadata

File hashes

Hashes for django_cookiebanner-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 32e6fa20429d580018911aed75a7c5a7fc120a63bf571bc6267b0f4a9a268e80
MD5 bccf725c796321027e9004efe91d92e9
BLAKE2b-256 6a8af543c462af597212b55f13f64f91745039293b9fdb8481a8ff78e7ec8fd3

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page