Skip to main content

Django''s application for handling privacy and cookie policies configured with Iubenda.

Project description

django-iubenda PyPi license

PyPi status PyPi version PyPi python version PyPi downloads PyPi downloads PyPi downloads

GitHub GitHub release GitHub release

Test codecov.io pre-commit.ci status gitthub.com

Compliance for websites and apps

Click here and get 10% discount on first year at Iubenda Iubenda

Check Demo Project

  • Check the demo repo on GitHub

Requirements

  • Python +3.8 supported.
  • Django +3.2 supported.

Setup

  1. Install from pip:
pip install django-iubenda
  1. Modify settings.py by adding the app to INSTALLED_APPS:
INSTALLED_APPS = (
    "modeltranslation",
    # ...
    "iubenda",
    # ...
)
  1. Modify settings.py by adding the app's context processor to TEMPLATES:
TEMPLATES = [
    {
        # ...
        "OPTIONS": {
            "context_processors": [
                # ...
                "iubenda.context_processors.iubenda",
                # ...
            ],
        },
    },
]
  1. Be sure the Django's Locale middleware is enabled inside settings.py:
MIDDLEWARE = (
    # ...
    "django.middleware.locale.LocaleMiddleware",
    # ...
)
  1. Optionally, but sugguested, the Django's Current Site middleware is enabled inside settings.py:
MIDDLEWARE = (
    # ...
    "django.contrib.sites.middleware.CurrentSiteMiddleware",
    # ...
)
  1. Modify url.py by adding the app's urls to urlpatterns:
urlpatterns += [
    path("", include("iubenda.urls")),
]
  1. Modify url.py by adding the app's sitemaps to sitemaps:
from iubenda.sitemaps import PrivacySitemap, CookieSitemap

sitemaps = {
    # ...
    "privacy": PrivacySitemap,
    "cookie": CookieSitemap,
    # ...
}
  1. Be sure the variable LANGUAGE_CODE is available for HTML templates:
{% load i18n %}
{% get_current_language as LANGUAGE_CODE %}
  1. 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 personalize the Iubenda script's 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",
    },
}

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-iubenda-1.4.0.tar.gz (74.9 kB view details)

Uploaded Source

Built Distribution

django_iubenda-1.4.0-py2.py3-none-any.whl (29.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-iubenda-1.4.0.tar.gz.

File metadata

  • Download URL: django-iubenda-1.4.0.tar.gz
  • Upload date:
  • Size: 74.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for django-iubenda-1.4.0.tar.gz
Algorithm Hash digest
SHA256 bc83e5c3bf6b63c3f44acce400ac069bd3d4bc2bc3658aff214c9c5d0b6106a5
MD5 3d383e92ca675dd5a1cd1c63e9c5c4e6
BLAKE2b-256 21a643203e74df78471c0eabb69358d364f1850fd6aaf01c8217b8f03f43c861

See more details on using hashes here.

File details

Details for the file django_iubenda-1.4.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_iubenda-1.4.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 bee44bee4336470b23e2e3ab8d1fcfe07b642e144660904712518c03a0f64a9b
MD5 5d0983e4fd7e54e0c8111efb8dc8b46e
BLAKE2b-256 c64d6f1798b125d0d07b8b840737da7f8e3f0ffcbd78d9d4a558096ec91ebfb3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page