Package: django-iubenda
django-iubendaGitHubTestCompliance for websites and appsClickhereand get 10% discount on first year at IubendaCheck Demo ProjectCheck the demo repo onGitHubRequirementsPython +3.8 supported.Django +3.2 supported.SetupInstall frompip:pipinstalldjango-iubendaModifysettings.pyby adding the app toINSTALLED_APPS:INSTALLED_APPS=("modeltranslation",# ..."iubenda",# ...)Modifysettings.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 insidesettings.py:MIDDLEWARE=(# ..."django.middleware.locale.LocaleMiddleware",# ...)Optionally, but sugguested, the Django's Current Site middleware is enabled insidesettings.py:MIDDLEWARE=(# ..."django.contrib.sites.middleware.CurrentSiteMiddleware",# ...)Modifyurl.pyby adding the app's urls tourlpatterns:urlpatterns+=[path("",include("iubenda.urls")),]Modifyurl.pyby adding the app's sitemaps tositemaps:fromiubenda.sitemapsimportPrivacySitemap,CookieSitemapsitemaps={# ..."privacy":PrivacySitemap,"cookie":CookieSitemap,# ...}Be sure the variableLANGUAGE_CODEis 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 thefooter.htmladd following code:{% if not debug %}
    {% block iubenda %}{% include "iubenda/include-content.html" %}{% endblock iubenda %}
{% endif %}OptionalContent Security PolicyIf Content Security Policy are implemented in your server and inline scripts are disabled,
the variableIUBENDA_CSP_NONCEcan be set with nonce tag will be inserted script's nonce.<scripttype="text/javascript"{%ifcx_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 allowunsafe-inlineinside 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 fromIubenda helpIubenda's OptionsTo personalize the Iubenda script's behaviour, the dictIUBENDA_OPTIONScan be configured insidesettings.pyIUBENDA_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",},}Integration with Google Tag ManagerIf Google Tag Manager is implemented in your application and all needed settings were configured inside the container,
the variableIUBENDA_GTMcan be set with the valueTrueand the Iubenda's callback will be inserted inside the script.For needed configuration inside Google Tag Manager container, please refer to these notes:Google Consent ModeGoogle Consent Mode setup GTM with IubendaGTM Blocking CookiesRun Example Projectgitclone--depth=50--branch=django-iubendahttps://github.com/DLRSP/example.gitDLRSP/examplecdDLRSP/example
pythonmanage.pyrunserverNow browser the app @http://127.0.0.1:8000