Django''s 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", # ... )
- Optionally, but sugguested, the Django's Current Site middleware is enabled inside
settings.py
:MIDDLEWARE = ( # ... "django.contrib.sites.middleware.CurrentSiteMiddleware", # ... )
- 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
Autoblocking
If Iubenda autoblocking's configurations are implemented in your account,
the variable IUBENDA_AUTOBLOCKING
can be set to import the site's script.
<script src="https://cs.iubenda.com/autoblocking/{{ cx_iubenda.iub_site_id }}.js"></script>
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 {% 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 personalize the Iubenda script's behaviour, the dict IUBENDA_OPTIONS
can be configured inside settings.py
IUBENDA_OPTIONS = {
"countryDetection": "true",
"askConsentAtCookiePolicyUpdate": "true",
"enableFadp": "true",
"enableLgpd": "true",
"lgpdAppliesGlobally": "true",
"enableUspr": "true",
"enableCcpa": "true",
"ccpaAcknowledgeOnDisplay": "true",
"ccpaApplies": "true",
"consentOnContinuedBrowsing": "false",
"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",
"showPurposesToggles": "true",
},
}
Integration with Google Tag Manager
If Google Tag Manager is implemented in your application and all needed settings were configured inside the container,
the variable IUBENDA_GTM
can be set with the value True
and the Iubenda's callback will be inserted inside the script.
For needed configuration inside Google Tag Manager container, please refer to these notes:
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
File details
Details for the file django_iubenda-1.6.4.tar.gz
.
File metadata
- Download URL: django_iubenda-1.6.4.tar.gz
- Upload date:
- Size: 45.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0f746aacbbe4812073deac67221989ffab35482dbfde77b6b637e541b6283ca |
|
MD5 | 9a788d50bd6d0c3feb51528cd778b9d0 |
|
BLAKE2b-256 | d6287ee783333a4daaeaee5ffa4fbcc9b43035da7dfa4c1c8062c801cf37937c |