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
Requirements
- Python 3.7 to 3.10 supported.
- Django 3.2 to 4.0 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 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 Distributions
Hashes for django_iubenda-0.1.12-py3.10.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1fc11901df789b44c875e2271ad76f4c87bc68878ea7824b6e500ccb753fa63d |
|
MD5 | 6b6fda52f3fa22b07d254556c7ea5fa1 |
|
BLAKE2b-256 | 8cd02a2624e3a49d55c0327b98b99b878549446249b8bedef8fb683e434cb04c |
Hashes for django_iubenda-0.1.12-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5068f2e3e30dca8d349aadb9063096d76d0013ccb3acf2b27d2942212002b0f3 |
|
MD5 | 582857b74d1d960531c1e67885c329bd |
|
BLAKE2b-256 | 9ef6aac5f5595ea3ae6f1743ede08e47af49508a55f85cff8e4c7b2f30a22e9c |