sinnwerkstatt / django-cookiebanner

GNU General Public License v3.0
10 stars 3 forks source link

Django-Cookiebanner

Installation

pip install django-cookiebanner

Usage

COOKIEBANNER = { "title": _("Cookie settings"), "headertext": ("We are using cookies on this website. A few are essential, others are not."), "footertext": ("Please accept our cookies"), "footerlinks": [ {"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:
```djangotemplate
{% 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.