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 or newer.
- Django 3.2 or newer (see package metadata for supported releases).
- django-requests-api (
requests_api) — shared HTTP client; typical import:from requests_api import RequestsApi, normalize_api_language, copy_get_params_with_overrides, requests_api_for_base.
Setup
- Install from pip:
pip install django-iubenda
- Modify
settings.pyby adding the apps toINSTALLED_APPS(same pattern as other DLRSP integrations that use django-requests-api):INSTALLED_APPS = ( "modeltranslation", # ... "requests_api", "iubenda", # ... )
- Modify
settings.pyby 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, enable Django’s CurrentSiteMiddleware in
settings.py:MIDDLEWARE = ( # ... "django.contrib.sites.middleware.CurrentSiteMiddleware", # ... )
- In
urls.py, include the app’s URLconf:urlpatterns += [ path("", include("iubenda.urls")), ]
- Register the app’s sitemaps (for example in
urls.pyor wherever you definesitemaps):from iubenda.sitemaps import PrivacySitemap, CookieSitemap sitemaps = { # ... "privacy": PrivacySitemap, "cookie": CookieSitemap, # ... }
- Be sure the variable
LANGUAGE_CODEis available for HTML templates:{% load i18n %} {% get_current_language as LANGUAGE_CODE %} - In your base layout or footer template, include the Iubenda fragment—for example in
footer.html:{% if not debug %} {% block iubenda %}{% include "iubenda/include-content.html" %}{% endblock iubenda %} {% endif %}
Configuration (APP_CONFIG and IUBENDA_*)
Options are resolved in iubenda.conf, consistent with other DLRSP apps (for example copyai):
- Top-level
IUBENDA_*(empty strings are skipped for string settings so the next source can apply). APP_CONFIG["iubenda"]— keys such asAPI_BASE_URL,API_ALLOWED_LANGS,API_FALLBACK_LANG,API_TIMEOUT,USE_COMPRESS,OPTIONS,GTM,CSP_NONCE,AUTOBLOCKING.- Defaults in
iubenda.defaults.
APP_CONFIG = {
"iubenda": {
"API_TIMEOUT": 45,
"GTM": True,
"OPTIONS": {"perPurposeConsent": "true"},
},
}
Full reference: docs/tutorial/configuration.md (MkDocs: Tutorials → Configuration (APP_CONFIG)). Optional APP_CONFIG["requests_api"] for django-requests-api is documented in that package; django-iubenda policy API timeouts stay under iubenda.conf (IUBENDA_API_TIMEOUT / API_TIMEOUT).
Optional
Autoblocking
If Iubenda autoblocking's configurations are implemented in your account,
set IUBENDA_AUTOBLOCKING or APP_CONFIG["iubenda"]["AUTOBLOCKING"] to enable the script.
<script src="https://cs.iubenda.com/autoblocking/{{ cx_iubenda.iub_site_id }}.js"></script>
Privacy and cookie API requests
The privacy and cookie views call Iubenda’s HTTP API with a lang query parameter aligned to request.LANGUAGE_CODE and to the languages your policies support. Values are read via iubenda.conf (IUBENDA_API_* and/or APP_CONFIG["iubenda"] keys API_BASE_URL, API_ALLOWED_LANGS, API_FALLBACK_LANG, API_TIMEOUT).
IUBENDA_API_BASE_URL/API_BASE_URL— base URL for API calls (default:https://www.iubenda.com).IUBENDA_API_ALLOWED_LANGS/API_ALLOWED_LANGS— allowedlangvalues (default:it,en).IUBENDA_API_FALLBACK_LANG/API_FALLBACK_LANG— used when the active language is not allowed (default:en).IUBENDA_API_TIMEOUT/API_TIMEOUT— seconds for API HTTP calls (default:30).
Use iubenda.api for Iubenda-specific helpers (they use iubenda.conf), or from requests_api import … for the shared client. Tutorials: docs/tutorial/http-api.md, docs/tutorial/configuration.md.
Content Security Policy
If you use a Content Security Policy and block inline scripts unless they carry a nonce, set IUBENDA_CSP_NONCE or APP_CONFIG["iubenda"]["CSP_NONCE"] so django-iubenda can render script tags with a nonce attribute. Your server or middleware must issue a fresh nonce per response and pass it into templates like your other inline scripts.
<script {% if cx_iubenda_nonce %}nonce="{{ cx_iubenda_nonce }}"{% endif %}>
Allow Iubenda hosts in the relevant CSP directives (script-src, connect-src, img-src, style-src, frame-src, etc.). Details depend on your stack; use Iubenda’s guide and your browser console. If you avoid 'unsafe-inline', you may need hash sources for specific snippets.
Iubenda: Content Security Policy and iubenda scripts
Iubenda options
Set IUBENDA_OPTIONS or APP_CONFIG["iubenda"]["OPTIONS"] in 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,
set IUBENDA_GTM = True or APP_CONFIG["iubenda"]["GTM"] = True so the Iubenda callback is inserted into 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_iubenda-1.7.4.tar.gz.
File metadata
- Download URL: django_iubenda-1.7.4.tar.gz
- Upload date:
- Size: 89.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4aede06f3880cc24ebd3cb14f7c48b732872b2ac78d779847def0e300aa5f74
|
|
| MD5 |
78da8e23016edcf0b95afdbf672a05c6
|
|
| BLAKE2b-256 |
6dc4bef87679e5334eee3e4af581a67203ef44338bfb9f00369744d44dbf9853
|
File details
Details for the file django_iubenda-1.7.4-py3-none-any.whl.
File metadata
- Download URL: django_iubenda-1.7.4-py3-none-any.whl
- Upload date:
- Size: 34.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a55b1cd5cbd859a0a9abb9a7373ad75caa53877fcc1874fe31004f73f120042
|
|
| MD5 |
e5709cf2b7c5d4495a8269e6e87ba044
|
|
| BLAKE2b-256 |
a8e68d97eb217555dfbc80345b85d5550ff591053d31042bd5ee146707fa232c
|