Django application for handling privacy and cookie policies configured with Iubenda.
Project description
django-iubenda
GitHub
Test
Compliance for websites and apps
Click here and get 10% discount on first year at Iubenda
Check Demo Project
- Check the demo repo on GitHub
Requirements
- Python +3.8 supported.
- Django +3.2 supported.
Setup
- Install from pip:
pip install django-iubenda
- Modify
settings.py
by adding the app toINSTALLED_APPS
:
INSTALLED_APPS = (
"modeltranslation",
# ...
"iubenda",
# ...
)
- Modify
settings.py
by adding the app's context processor toTEMPLATES
:
TEMPLATES = [
{
# ...
"OPTIONS": {
"context_processors": [
# ...
"iubenda.context_processors.iubenda",
# ...
],
},
},
]
- Be sure the Django's Locale middleware is enabled inside
settings.py
:
MIDDLEWARE = (
# ...
"django.middleware.locale.LocaleMiddleware",
# ...
)
- Modify
url.py
by adding the app's urls tourlpatterns
:
urlpatterns += [
path("", include("iubenda.urls")),
]
- Modify
url.py
by adding the app's sitemaps tositemaps
:
from iubenda.sitemaps import PrivacySitemap, CookieSitemap
sitemaps = {
# ...
"privacy": PrivacySitemap,
"cookie": CookieSitemap,
# ...
}
- Be sure the variable
LANGUAGE_CODE
is available for HTML templates:
{% load i18n %}
{% get_current_language as LANGUAGE_CODE %}
- Modify your project's template to add privacy and cookie policies.
For example inside the
footer.html
add following code:
{% if not debug %}
{% block iubenda %}{% include "iubenda/include-content.html" %}{% endblock iubenda %}
{% endif %}
Optional
Content Security Policy
If Content Security Policy are implemented in your server and inline scripts are disabled,
the variable IUBENDA_CSP_NONCE
can be set with nonce tag will be inserted script's nonce.
<script type="text/javascript" {% if cx_iubenda_nonce %}nonce="{{ cx_iubenda_nonce }}"{% endif %}>
Inside your webserver's configurations, a rule to dynamically replace your CONSTANT nonce in a random string is needed.
To allow external source from Iubenda domains, please implement these rules:
Content-Security-Policy:
script-src-elem https://*.iubenda.com";
img-src https://*.iubenda.com data:";
style-src https://*.iubenda.com";
connect-src https://*.iubenda.com";
frame-src https://*.iubenda.com";
If you prefer to not allow unsafe-inline inside your CSP, please also add the two specific hash for your script prompted as error in Javascript Console.
# Iubenda Privacy And Cookie Policy - API
Content-Security-Policy:
...
script-src-elem https://*.iubenda.com 'sha256-YOUR-FIRST-HASH-PROMPTED-INSIDE-CONSOLE' 'sha256-YOUR-SECOND-HASH-PROMPTED-INSIDE-CONSOLE';
...
Check this article from Iubenda help
Iubenda's Options
(To-Do: new feuture)
To personalize the Iubenda script behaviour, the dict IUBENDA_OPTIONS
can be configured inside settings.py
IUBENDA_OPTIONS = {
"ccpaAcknowledgeOnDisplay": "true",
"ccpaApplies": "true",
"consentOnContinuedBrowsing": "false",
"enableCcpa": "true",
"floatingPreferencesButtonDisplay": "bottom-left",
"invalidateConsentWithoutLog": "true",
"perPurposeConsent": "true",
"whitelabel": "false",
"banner": {
"acceptButtonDisplay": "true",
"backgroundOverlay": "true",
"closeButtonRejects": "true",
"customizeButtonDisplay": "true",
"explicitWithdrawal": "true",
"fontSize": "14px",
"listPurposes": "true",
"position": "float-center",
"rejectButtonDisplay": "true",
},
}
Run Example Project
git clone --depth=50 --branch=django-iubenda https://github.com/DLRSP/example.git DLRSP/example
cd DLRSP/example
python manage.py runserver
Now browser the app @ http://127.0.0.1:8000
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-iubenda-1.2.10.tar.gz
.
File metadata
- Download URL: django-iubenda-1.2.10.tar.gz
- Upload date:
- Size: 56.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c2d6133a154a7f7de1c531eab08f3d813f2c4b3190d83f5c6c9ad7831533c52 |
|
MD5 | d455c29bfa68d35add0235cd8174ec38 |
|
BLAKE2b-256 | d4f262987f5c158086b1c2ca792c7b0e6cf960266d3e4e9c0d8dfef082958a53 |
File details
Details for the file django_iubenda-1.2.10-py2.py3-none-any.whl
.
File metadata
- Download URL: django_iubenda-1.2.10-py2.py3-none-any.whl
- Upload date:
- Size: 28.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d0e2a8a288cfb37d412941fa080660b02651a15f8db74787a6184f766ac8f30 |
|
MD5 | a7afd373c2d7bc90b6e47ea7838b1771 |
|
BLAKE2b-256 | 2666b4c244c13b170bfca1376f3f49a909f0e250bbb74adbfe755b71cb9b4d9a |