diff --git a/docs/getting-started/index.html b/docs/getting-started/index.html index 53cbf14..40fdbe0 100644 --- a/docs/getting-started/index.html +++ b/docs/getting-started/index.html @@ -122,7 +122,7 @@

1. Download and install the

Get Django GDPR Cookie Consent from Gumroad.

Create a directory private_wheels/ in your project's repository and add the wheel file of the app there.

Link to this file in your requirements.txt:

-
Django==4.2
+
Django==5.0
 file:./private_wheels/django_gdpr_cookie_consent-2.2.0-py2.py3-none-any.whl
 

Install the pip requirements from the requirements.txt file into your project's virtual environment:

diff --git a/docs/index.html b/docs/index.html index bb8caaf..bb88d0e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -317,5 +317,5 @@ diff --git a/docs/search/search_index.json b/docs/search/search_index.json index c83d560..ec3c7d4 100644 --- a/docs/search/search_index.json +++ b/docs/search/search_index.json @@ -1 +1 @@ -{"config":{"indexing":"full","lang":["en"],"min_search_length":3,"prebuild_index":false,"separator":"[\\s\\-]+"},"docs":[{"location":"","text":"Django GDPR Cookie Consent Why do you need it? As stated by GDPR cookie law , websites that serve content for people from European Union must get consent from website visitors before storing any cookies that are not strictly necessary for the website to function. Not complying with GDPR laws can result in a fine of up to \u20ac20 million or 4% of the company's annual revenue, whichever is greater. Who is it for? Django GDPR Cookie Consent app was created for Django developers who need to integrate a Cookie Consent dialog in their Django projects. The existing open-source Django alternatives at the time of writing were not fully compliant or not feature complete. In addition, the current external services were costly and not customizable enough. Feature Value Supported modern browsers Chrome, Firefox, Safari, Opera, Microsoft Edge Supported Django versions 2.2, 3.0, 3.1, 3.2, 4.0, 4.1, 4.2, 5.0 Supported Python versions 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12 Responsive layout \u2714\ufe0e Multiple layout options \u2714\ufe0e Translatable \u2714\ufe0e Configurable \u2714\ufe0e Unlimited websites \u2714\ufe0e Continuous cookie consent logs \u2714\ufe0e Anonymized IP addresses in the logs \u2714\ufe0e Latest package version 2.2.0 What are the benefits? There are lots of benefits: Saves at least a week of development work. Highly flexible and configurable. Can be used for as many Django websites as necessary. Easy to copy the configuration from one project to another. No external dependencies, just Django>=2.2, Python 3, and plain modern JavaScript. Comes with pretty nice-looking default styling and a responsive layout. Typography and buttons will match your website's style (no iframes used). All functionality can be extended, overwritten, or replaced. Uses configuration in Django settings and templates. No need to modify or adapt scripts from third parties (most of the time). Logs the cookie consent choices from visitors into the database for legal compliance. Developed with internationalization in mind. Compatible with Content-Security-Policy via Django-CSP. MIT license applied. No recurring subscriptions, no limitation per domain, just a single payment. Designed and implemented by the author of \"Web development with Django Cookbook.\" How does it work? Django GDPR Cookie Consent app allows you to set up a modal dialog for cookie explanations and preferences. When a specific cookie section is accepted, the widget loads or renders HTML snippets related to that section. For example, if a visitor approved Performance cookies, they would get Google Analytics loaded. Using the Django GDPR Cookie Consent app, you store the following information about the cookies in Django project settings: What are the cookie sections (e.g. \"Essential\", \"Functionality\", \"Performance\", \"Marketing\")? Are they bounded with any conditional HTML snippets? What are the cookie providers within each section (e.g., \"This website,\" \"Google Analytics,\" \"Facebook,\" \"Youtube,\" etc.)? What are the cookies set by each of those providers? Descriptions for sections, providers, or cookies are translatable. User preferences are saved in a cookie too. If a particular section is unselected later, cookies related to that section are attempted to get deleted. Examples Here are the recorded Selenium tests for a visual preview: Django GDPR Cookie Consent is used in production at these websites: 1st things 1st DjangoTricks Disclaimer The actual website's compliance with the GDPR Cookie Law depends on the configuration of each use case. Django GDPR Cookie Consent app provides the mechanism to make that possible, but it's up to you how you configure and integrate it. Contact For technical questions, feature requests, or bug reports, please contact Aidas Bendoraitis at https://www.djangotricks.com/feedback/ .","title":"Home"},{"location":"#django-gdpr-cookie-consent","text":"","title":"Django GDPR Cookie Consent"},{"location":"#why-do-you-need-it","text":"As stated by GDPR cookie law , websites that serve content for people from European Union must get consent from website visitors before storing any cookies that are not strictly necessary for the website to function. Not complying with GDPR laws can result in a fine of up to \u20ac20 million or 4% of the company's annual revenue, whichever is greater.","title":"Why do you need it?"},{"location":"#who-is-it-for","text":"Django GDPR Cookie Consent app was created for Django developers who need to integrate a Cookie Consent dialog in their Django projects. The existing open-source Django alternatives at the time of writing were not fully compliant or not feature complete. In addition, the current external services were costly and not customizable enough. Feature Value Supported modern browsers Chrome, Firefox, Safari, Opera, Microsoft Edge Supported Django versions 2.2, 3.0, 3.1, 3.2, 4.0, 4.1, 4.2, 5.0 Supported Python versions 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12 Responsive layout \u2714\ufe0e Multiple layout options \u2714\ufe0e Translatable \u2714\ufe0e Configurable \u2714\ufe0e Unlimited websites \u2714\ufe0e Continuous cookie consent logs \u2714\ufe0e Anonymized IP addresses in the logs \u2714\ufe0e Latest package version 2.2.0","title":"Who is it for?"},{"location":"#what-are-the-benefits","text":"There are lots of benefits: Saves at least a week of development work. Highly flexible and configurable. Can be used for as many Django websites as necessary. Easy to copy the configuration from one project to another. No external dependencies, just Django>=2.2, Python 3, and plain modern JavaScript. Comes with pretty nice-looking default styling and a responsive layout. Typography and buttons will match your website's style (no iframes used). All functionality can be extended, overwritten, or replaced. Uses configuration in Django settings and templates. No need to modify or adapt scripts from third parties (most of the time). Logs the cookie consent choices from visitors into the database for legal compliance. Developed with internationalization in mind. Compatible with Content-Security-Policy via Django-CSP. MIT license applied. No recurring subscriptions, no limitation per domain, just a single payment. Designed and implemented by the author of \"Web development with Django Cookbook.\"","title":"What are the benefits?"},{"location":"#how-does-it-work","text":"Django GDPR Cookie Consent app allows you to set up a modal dialog for cookie explanations and preferences. When a specific cookie section is accepted, the widget loads or renders HTML snippets related to that section. For example, if a visitor approved Performance cookies, they would get Google Analytics loaded. Using the Django GDPR Cookie Consent app, you store the following information about the cookies in Django project settings: What are the cookie sections (e.g. \"Essential\", \"Functionality\", \"Performance\", \"Marketing\")? Are they bounded with any conditional HTML snippets? What are the cookie providers within each section (e.g., \"This website,\" \"Google Analytics,\" \"Facebook,\" \"Youtube,\" etc.)? What are the cookies set by each of those providers? Descriptions for sections, providers, or cookies are translatable. User preferences are saved in a cookie too. If a particular section is unselected later, cookies related to that section are attempted to get deleted.","title":"How does it work?"},{"location":"#examples","text":"Here are the recorded Selenium tests for a visual preview: Django GDPR Cookie Consent is used in production at these websites: 1st things 1st DjangoTricks","title":"Examples"},{"location":"#disclaimer","text":"The actual website's compliance with the GDPR Cookie Law depends on the configuration of each use case. Django GDPR Cookie Consent app provides the mechanism to make that possible, but it's up to you how you configure and integrate it.","title":"Disclaimer"},{"location":"#contact","text":"For technical questions, feature requests, or bug reports, please contact Aidas Bendoraitis at https://www.djangotricks.com/feedback/ .","title":"Contact"},{"location":"CHANGELOG/","text":"Changelog All notable changes to this project will be documented in this file. The format is based on Keep a Changelog , and this project adheres to Semantic Versioning . [Unreleased] [v2.2.0] - 2024-03-08 Added Django 5.0 support. Python 3.9, 3.10, 3.11, 3.12 support. [v2.1.0] - 2023-04-07 Added Django 4.2 support. [v2.0.1] - 2022-10-31 Fixed Python 3.5, 3.6, 3.7, 3.8 support. [v2.0.0] - 2022-10-31 Added Button text customization. Possibility to preselect a section in configuration. IP addresses in the logs anonymized. Python 3.11 support. Dialog position configurations: center, top, left, right, bottom. Changed Dialog close button made optional and not shown by default. [v1.2.1] - 2022-09-14 Added Pointer cursor for \"Show cookie providers\". Fixed gettext_lazy usage in the settings. [v1.2.0] - 2022-08-07 Added Django 4.1 support. [v1.1.0] - 2021-12-17 Added Django 4.0 support. [v1.0.0] - 2021-11-15 Added Python 3.9 and 3.10 support. [v0.3.2] - 2021-11-14 Fixed More spacious layout for the modal dialog on mobile screens. [v0.3.1] - 2021-11-12 Fixed The styling for the modal dialog close button fixed for mobile Chrome and Safari. [v0.3.0] - 2021-11-12 Added Content-Security-Policy is supported: you can use Django-CSP with nonces for inline scripts and styles. [v0.2.4] - 2021-11-02 Added HTML ids added for switch widgets for easier testability. [v0.2.3] - 2021-11-01 Fixed Modal dialog submission fix for Safari. [v0.2.2] - 2021-11-01 Fixed Multiple Then check for that value in some rendering functions: // some javascript file if (window.ENABLE_YOUTUBE_EMBEDS) { embed_youtube_videos(); } Using Content-Security-Policy with Django-CSP Django GDPR Cookie Consent is compatible with Content-Security-Policy via Django-CSP app. To use it together, you just need to do two things. In the project's settings, enable nonces: CSP_INCLUDE_NONCE_IN = [\"script-src\", \"style-src\"] In the conditional html snippets, set nonces for inline ","title":"Customization"},{"location":"customization/#customization","text":"","title":"Customization"},{"location":"customization/#descriptions","text":"Each description in the COOKIE_CONSENT_SETTINGS configuration can be either set as description translatable string, or as a description_template_name template path with any necessary HTML markup.","title":"Descriptions"},{"location":"customization/#layout-options","text":"There are five possible modal dialog layout options, set as the dialog_position setting: center - a dialog box is shown in the middle of the window. top - a dialog is at the full-width top bar. left - a dialog is at the left sidebar. right - a dialog is at the right sidebar. bottom - a dialog is at the full-width bottom bar. The show_dialog_close_button setting tells whether to show or hide the close button for the dialog. Setting it to False is recommended because you need somewhat consent before activating JavaScript functionalities on your websites as soon as possible.","title":"Layout options"},{"location":"customization/#button-texts","text":"Button texts can be cusomized by the buttons setting: \"buttons\": { \"accept_all_dialog\": _(\"Accept all\"), \"reject_all_dialog\": _(\"Reject all\"), \"manage_cookies\": _(\"Manage cookies\"), \"accept_all_config\": _(\"Accept all\"), \"reject_all_config\": _(\"Reject all\"), \"save_preferences\": _(\"Save preferences\"), \"save_and_close\": _(\"Save and close\"), \"close\": _(\"Close\"), },","title":"Button texts"},{"location":"customization/#styling","text":"The modal dialog uses the fonts of the website. Colors can be modified by CSS custom properties: body { --cc-primary: #007bff; --cc-light-gray: #ccc; --cc-dark-gray: #343a40; --cc-light: #fff; --cc-backdrop: rgba(0, 0, 0, 0.5); } All essential elements have CSS classes with cc- prefix, and you can overwrite some of their properties. If you are using a CSS framework like Bootstrap or TailwindCSS, you can set the extra CSS classes for particular elements in the styling section of COOKIE_CONSENT_SETTINGS : \"styling\": { \"primary_button_css_classes\": \"\", \"secondary_button_css_classes\": \"\", \"provider_list_css_classes\": \"\", \"provider_item_css_classes\": \"\", \"link_css_classes\": \"\", \"section_anchor_css_classes\": \"\", }, If you can't implement what you need with the methods above, instead you can create a custom CSS file and link to it. And of that is still not an option for you, you can also overwrite the templates.","title":"Styling"},{"location":"customization/#templates","text":"The templates used for the cookie consent management can be copied to the templates directory of the project and overwritten. Mostly necessary templates are these: gdpr_cookie_consent/descriptions/what_are_cookies.html is the description of the cookies in the modal dialog and cookie management page. gdpr_cookie_consent/descriptions/extra.html is the extra HTML going at the bottom of cookie management page. gdpr_cookie_consent/modal_dialog.html is the template for the cookie consent's modal dialog. gdpr_cookie_consent/cookies_management.html is the template for the external page.","title":"Templates"},{"location":"customization/#passing-variables-to-cookie-consent-management-templates","text":"If you don't want to hardcode some variables like API keys in the conditional HTML files, you can pass them in extra_context section of COOKIE_CONSENT_SETTINGS : \"extra_context\": { \"GOOGLE_ANALYTICS_TRACKING_ID\": get_secret(\"GOOGLE_ANALYTICS_TRACKING_ID\"), \"STRIPE_PUBLISHABLE_KEY\": get_secret(\"STRIPE_PUBLISHABLE_KEY\"), }, In this example, get_secret() should be a function implemented by you, that reads the secret values from the environment variables, unversioned secrets.json file, or elsewhere. The variables mentioned in extra_context will be passed to all templates of Django GDPR Cookie Consent.","title":"Passing Variables to Cookie Consent Management Templates"},{"location":"customization/#conditional-rendering-in-templates","text":"Enable gdpr_cookie_consent context processor in the template settings: TEMPLATES = [ { # \u2026 \"OPTIONS\": { \"context_processors\": [ # \u2026 \"gdpr_cookie_consent.context_processors.gdpr_cookie_consent\", ], }, }, ] Now you can check if a section was chosen by the visitor in any template by this: {% if \"functionality\" in cookie_consent_controller.checked_sections %} {% endif %} Note that this conditional rendering will happen only after page reload, not just after closing the Cookie Consent modal dialog.","title":"Conditional Rendering in Templates"},{"location":"customization/#conditional-rendering-in-javascript","text":"If you are using ReactJS, Vue, AngularJS, or other frontend library to render HTML, you can check if a cookie section was chosen by the following technique. At first set a global variable in conditional templates: {# conditional_html/functionality.html #} Then check for that value in some rendering functions: // some javascript file if (window.ENABLE_YOUTUBE_EMBEDS) { embed_youtube_videos(); }","title":"Conditional Rendering in JavaScript"},{"location":"customization/#using-content-security-policy-with-django-csp","text":"Django GDPR Cookie Consent is compatible with Content-Security-Policy via Django-CSP app. To use it together, you just need to do two things. In the project's settings, enable nonces: CSP_INCLUDE_NONCE_IN = [\"script-src\", \"style-src\"] In the conditional html snippets, set nonces for inline ","title":"Using Content-Security-Policy with Django-CSP"},{"location":"getting-started/","text":"Getting Started How to Install 1. Download and install the package with pip Get Django GDPR Cookie Consent from Gumroad . Create a directory private_wheels/ in your project's repository and add the wheel file of the app there. Link to this file in your requirements.txt : Django==4.2 file:./private_wheels/django_gdpr_cookie_consent-2.2.0-py2.py3-none-any.whl Install the pip requirements from the requirements.txt file into your project's virtual environment: (venv)$ pip install -r requirements.txt Alternatively to start quickly, install the wheel file into your Django project's virtual environment right from the shell: (venv)$ pip install /path/to/django_gdpr_cookie_consent-2.2.0-py2.py3-none-any.whl 2. Add the app to INSTALLED_APPS of your project settings INSTALLED_APPS = [ # \u2026 \"gdpr_cookie_consent.apps.GdprCookieConsentConfig\", # \u2026 ] 3. Add path to urlpatterns from django.urls import path, include urlpatterns = [ # \u2026 path( \"cookies/\", include(\"gdpr_cookie_consent.urls\", namespace=\"cookie_consent\"), ), # \u2026 ] 4. Include the widget to your template(s) Load the CSS somewhere in the section: Include the widget just before the closing tag: {% include \"gdpr_cookie_consent/includes/cookie_consent.html\" %} Link to the cookie management view, for example, in the website's footer: {% url \"cookie_consent:cookies_management\" as cookie_management_url %} {% trans \"Manage Cookies\" %} How to Use 1. Copy, paste, and modify the cookie consent configuration Copy the example of COOKIE_CONSENT_SETTINGS to the end of your project settings, then modify it to match the cookie usage of your website. In the example above, there are four cookie sections: Essential (strictly necessary), Functionality (optional), Performance (optional), and Marketing (optional). 2. Create templates to render HTML for non-required cookies Cookies that are set conditionally based upon a visitor\u2019s choices must be rendered from conditional templates. For example, analytics providers typically instruct to place the analytics tag within the page\u2019s section. However, suppose visitors are being given a choice of whether to accept analytics cookies using Django GDPR Cookie Consent. In that case, the analytics tag that sets the analytics cookies must be rendered from conditional templates. The conditional HTML might include external or inline styles, external or inline JavaScripts, and other HTML snippets. Create templates for the snippets that will be loaded or rendered when a particular section is chosen, for example: conditional_html/functionality.html conditional_html/performance.html conditional_html/marketing.html For testing, you can add the markup like: Manage the scripts that create your Essential (strictly necessary) cookies separately, unrelated to conditional html snippets. 3. Translate your titles and descriptions If your website has more than one language, prepare the translations: Use management command makemessages to collect translatable strings into django.po files. Translate the strings to the languages you need. Then, use the management command compilemessages to compile them to django.mo files.","title":"Getting Started"},{"location":"getting-started/#getting-started","text":"","title":"Getting Started"},{"location":"getting-started/#how-to-install","text":"","title":"How to Install"},{"location":"getting-started/#1-download-and-install-the-package-with-pip","text":"Get Django GDPR Cookie Consent from Gumroad . Create a directory private_wheels/ in your project's repository and add the wheel file of the app there. Link to this file in your requirements.txt : Django==4.2 file:./private_wheels/django_gdpr_cookie_consent-2.2.0-py2.py3-none-any.whl Install the pip requirements from the requirements.txt file into your project's virtual environment: (venv)$ pip install -r requirements.txt Alternatively to start quickly, install the wheel file into your Django project's virtual environment right from the shell: (venv)$ pip install /path/to/django_gdpr_cookie_consent-2.2.0-py2.py3-none-any.whl","title":"1. Download and install the package with pip"},{"location":"getting-started/#2-add-the-app-to-installed_apps-of-your-project-settings","text":"INSTALLED_APPS = [ # \u2026 \"gdpr_cookie_consent.apps.GdprCookieConsentConfig\", # \u2026 ]","title":"2. Add the app to INSTALLED_APPS of your project settings"},{"location":"getting-started/#3-add-path-to-urlpatterns","text":"from django.urls import path, include urlpatterns = [ # \u2026 path( \"cookies/\", include(\"gdpr_cookie_consent.urls\", namespace=\"cookie_consent\"), ), # \u2026 ]","title":"3. Add path to urlpatterns"},{"location":"getting-started/#4-include-the-widget-to-your-templates","text":"Load the CSS somewhere in the section: Include the widget just before the closing tag: {% include \"gdpr_cookie_consent/includes/cookie_consent.html\" %} Link to the cookie management view, for example, in the website's footer: {% url \"cookie_consent:cookies_management\" as cookie_management_url %} {% trans \"Manage Cookies\" %} ","title":"4. Include the widget to your template(s)"},{"location":"getting-started/#how-to-use","text":"","title":"How to Use"},{"location":"getting-started/#1-copy-paste-and-modify-the-cookie-consent-configuration","text":"Copy the example of COOKIE_CONSENT_SETTINGS to the end of your project settings, then modify it to match the cookie usage of your website. In the example above, there are four cookie sections: Essential (strictly necessary), Functionality (optional), Performance (optional), and Marketing (optional).","title":"1. Copy, paste, and modify the cookie consent configuration"},{"location":"getting-started/#2-create-templates-to-render-html-for-non-required-cookies","text":"Cookies that are set conditionally based upon a visitor\u2019s choices must be rendered from conditional templates. For example, analytics providers typically instruct to place the analytics tag within the page\u2019s section. However, suppose visitors are being given a choice of whether to accept analytics cookies using Django GDPR Cookie Consent. In that case, the analytics tag that sets the analytics cookies must be rendered from conditional templates. The conditional HTML might include external or inline styles, external or inline JavaScripts, and other HTML snippets. Create templates for the snippets that will be loaded or rendered when a particular section is chosen, for example: conditional_html/functionality.html conditional_html/performance.html conditional_html/marketing.html For testing, you can add the markup like: Manage the scripts that create your Essential (strictly necessary) cookies separately, unrelated to conditional html snippets.","title":"2. Create templates to render HTML for non-required cookies"},{"location":"getting-started/#3-translate-your-titles-and-descriptions","text":"If your website has more than one language, prepare the translations: Use management command makemessages to collect translatable strings into django.po files. Translate the strings to the languages you need. Then, use the management command compilemessages to compile them to django.mo files.","title":"3. Translate your titles and descriptions"}]} \ No newline at end of file +{"config":{"indexing":"full","lang":["en"],"min_search_length":3,"prebuild_index":false,"separator":"[\\s\\-]+"},"docs":[{"location":"","text":"Django GDPR Cookie Consent Why do you need it? As stated by GDPR cookie law , websites that serve content for people from European Union must get consent from website visitors before storing any cookies that are not strictly necessary for the website to function. Not complying with GDPR laws can result in a fine of up to \u20ac20 million or 4% of the company's annual revenue, whichever is greater. Who is it for? Django GDPR Cookie Consent app was created for Django developers who need to integrate a Cookie Consent dialog in their Django projects. The existing open-source Django alternatives at the time of writing were not fully compliant or not feature complete. In addition, the current external services were costly and not customizable enough. Feature Value Supported modern browsers Chrome, Firefox, Safari, Opera, Microsoft Edge Supported Django versions 2.2, 3.0, 3.1, 3.2, 4.0, 4.1, 4.2, 5.0 Supported Python versions 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12 Responsive layout \u2714\ufe0e Multiple layout options \u2714\ufe0e Translatable \u2714\ufe0e Configurable \u2714\ufe0e Unlimited websites \u2714\ufe0e Continuous cookie consent logs \u2714\ufe0e Anonymized IP addresses in the logs \u2714\ufe0e Latest package version 2.2.0 What are the benefits? There are lots of benefits: Saves at least a week of development work. Highly flexible and configurable. Can be used for as many Django websites as necessary. Easy to copy the configuration from one project to another. No external dependencies, just Django>=2.2, Python 3, and plain modern JavaScript. Comes with pretty nice-looking default styling and a responsive layout. Typography and buttons will match your website's style (no iframes used). All functionality can be extended, overwritten, or replaced. Uses configuration in Django settings and templates. No need to modify or adapt scripts from third parties (most of the time). Logs the cookie consent choices from visitors into the database for legal compliance. Developed with internationalization in mind. Compatible with Content-Security-Policy via Django-CSP. MIT license applied. No recurring subscriptions, no limitation per domain, just a single payment. Designed and implemented by the author of \"Web development with Django Cookbook.\" How does it work? Django GDPR Cookie Consent app allows you to set up a modal dialog for cookie explanations and preferences. When a specific cookie section is accepted, the widget loads or renders HTML snippets related to that section. For example, if a visitor approved Performance cookies, they would get Google Analytics loaded. Using the Django GDPR Cookie Consent app, you store the following information about the cookies in Django project settings: What are the cookie sections (e.g. \"Essential\", \"Functionality\", \"Performance\", \"Marketing\")? Are they bounded with any conditional HTML snippets? What are the cookie providers within each section (e.g., \"This website,\" \"Google Analytics,\" \"Facebook,\" \"Youtube,\" etc.)? What are the cookies set by each of those providers? Descriptions for sections, providers, or cookies are translatable. User preferences are saved in a cookie too. If a particular section is unselected later, cookies related to that section are attempted to get deleted. Examples Here are the recorded Selenium tests for a visual preview: Django GDPR Cookie Consent is used in production at these websites: 1st things 1st DjangoTricks Disclaimer The actual website's compliance with the GDPR Cookie Law depends on the configuration of each use case. Django GDPR Cookie Consent app provides the mechanism to make that possible, but it's up to you how you configure and integrate it. Contact For technical questions, feature requests, or bug reports, please contact Aidas Bendoraitis at https://www.djangotricks.com/feedback/ .","title":"Home"},{"location":"#django-gdpr-cookie-consent","text":"","title":"Django GDPR Cookie Consent"},{"location":"#why-do-you-need-it","text":"As stated by GDPR cookie law , websites that serve content for people from European Union must get consent from website visitors before storing any cookies that are not strictly necessary for the website to function. Not complying with GDPR laws can result in a fine of up to \u20ac20 million or 4% of the company's annual revenue, whichever is greater.","title":"Why do you need it?"},{"location":"#who-is-it-for","text":"Django GDPR Cookie Consent app was created for Django developers who need to integrate a Cookie Consent dialog in their Django projects. The existing open-source Django alternatives at the time of writing were not fully compliant or not feature complete. In addition, the current external services were costly and not customizable enough. Feature Value Supported modern browsers Chrome, Firefox, Safari, Opera, Microsoft Edge Supported Django versions 2.2, 3.0, 3.1, 3.2, 4.0, 4.1, 4.2, 5.0 Supported Python versions 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12 Responsive layout \u2714\ufe0e Multiple layout options \u2714\ufe0e Translatable \u2714\ufe0e Configurable \u2714\ufe0e Unlimited websites \u2714\ufe0e Continuous cookie consent logs \u2714\ufe0e Anonymized IP addresses in the logs \u2714\ufe0e Latest package version 2.2.0","title":"Who is it for?"},{"location":"#what-are-the-benefits","text":"There are lots of benefits: Saves at least a week of development work. Highly flexible and configurable. Can be used for as many Django websites as necessary. Easy to copy the configuration from one project to another. No external dependencies, just Django>=2.2, Python 3, and plain modern JavaScript. Comes with pretty nice-looking default styling and a responsive layout. Typography and buttons will match your website's style (no iframes used). All functionality can be extended, overwritten, or replaced. Uses configuration in Django settings and templates. No need to modify or adapt scripts from third parties (most of the time). Logs the cookie consent choices from visitors into the database for legal compliance. Developed with internationalization in mind. Compatible with Content-Security-Policy via Django-CSP. MIT license applied. No recurring subscriptions, no limitation per domain, just a single payment. Designed and implemented by the author of \"Web development with Django Cookbook.\"","title":"What are the benefits?"},{"location":"#how-does-it-work","text":"Django GDPR Cookie Consent app allows you to set up a modal dialog for cookie explanations and preferences. When a specific cookie section is accepted, the widget loads or renders HTML snippets related to that section. For example, if a visitor approved Performance cookies, they would get Google Analytics loaded. Using the Django GDPR Cookie Consent app, you store the following information about the cookies in Django project settings: What are the cookie sections (e.g. \"Essential\", \"Functionality\", \"Performance\", \"Marketing\")? Are they bounded with any conditional HTML snippets? What are the cookie providers within each section (e.g., \"This website,\" \"Google Analytics,\" \"Facebook,\" \"Youtube,\" etc.)? What are the cookies set by each of those providers? Descriptions for sections, providers, or cookies are translatable. User preferences are saved in a cookie too. If a particular section is unselected later, cookies related to that section are attempted to get deleted.","title":"How does it work?"},{"location":"#examples","text":"Here are the recorded Selenium tests for a visual preview: Django GDPR Cookie Consent is used in production at these websites: 1st things 1st DjangoTricks","title":"Examples"},{"location":"#disclaimer","text":"The actual website's compliance with the GDPR Cookie Law depends on the configuration of each use case. Django GDPR Cookie Consent app provides the mechanism to make that possible, but it's up to you how you configure and integrate it.","title":"Disclaimer"},{"location":"#contact","text":"For technical questions, feature requests, or bug reports, please contact Aidas Bendoraitis at https://www.djangotricks.com/feedback/ .","title":"Contact"},{"location":"CHANGELOG/","text":"Changelog All notable changes to this project will be documented in this file. The format is based on Keep a Changelog , and this project adheres to Semantic Versioning . [Unreleased] [v2.2.0] - 2024-03-08 Added Django 5.0 support. Python 3.9, 3.10, 3.11, 3.12 support. [v2.1.0] - 2023-04-07 Added Django 4.2 support. [v2.0.1] - 2022-10-31 Fixed Python 3.5, 3.6, 3.7, 3.8 support. [v2.0.0] - 2022-10-31 Added Button text customization. Possibility to preselect a section in configuration. IP addresses in the logs anonymized. Python 3.11 support. Dialog position configurations: center, top, left, right, bottom. Changed Dialog close button made optional and not shown by default. [v1.2.1] - 2022-09-14 Added Pointer cursor for \"Show cookie providers\". Fixed gettext_lazy usage in the settings. [v1.2.0] - 2022-08-07 Added Django 4.1 support. [v1.1.0] - 2021-12-17 Added Django 4.0 support. [v1.0.0] - 2021-11-15 Added Python 3.9 and 3.10 support. [v0.3.2] - 2021-11-14 Fixed More spacious layout for the modal dialog on mobile screens. [v0.3.1] - 2021-11-12 Fixed The styling for the modal dialog close button fixed for mobile Chrome and Safari. [v0.3.0] - 2021-11-12 Added Content-Security-Policy is supported: you can use Django-CSP with nonces for inline scripts and styles. [v0.2.4] - 2021-11-02 Added HTML ids added for switch widgets for easier testability. [v0.2.3] - 2021-11-01 Fixed Modal dialog submission fix for Safari. [v0.2.2] - 2021-11-01 Fixed Multiple Then check for that value in some rendering functions: // some javascript file if (window.ENABLE_YOUTUBE_EMBEDS) { embed_youtube_videos(); } Using Content-Security-Policy with Django-CSP Django GDPR Cookie Consent is compatible with Content-Security-Policy via Django-CSP app. To use it together, you just need to do two things. In the project's settings, enable nonces: CSP_INCLUDE_NONCE_IN = [\"script-src\", \"style-src\"] In the conditional html snippets, set nonces for inline ","title":"Customization"},{"location":"customization/#customization","text":"","title":"Customization"},{"location":"customization/#descriptions","text":"Each description in the COOKIE_CONSENT_SETTINGS configuration can be either set as description translatable string, or as a description_template_name template path with any necessary HTML markup.","title":"Descriptions"},{"location":"customization/#layout-options","text":"There are five possible modal dialog layout options, set as the dialog_position setting: center - a dialog box is shown in the middle of the window. top - a dialog is at the full-width top bar. left - a dialog is at the left sidebar. right - a dialog is at the right sidebar. bottom - a dialog is at the full-width bottom bar. The show_dialog_close_button setting tells whether to show or hide the close button for the dialog. Setting it to False is recommended because you need somewhat consent before activating JavaScript functionalities on your websites as soon as possible.","title":"Layout options"},{"location":"customization/#button-texts","text":"Button texts can be cusomized by the buttons setting: \"buttons\": { \"accept_all_dialog\": _(\"Accept all\"), \"reject_all_dialog\": _(\"Reject all\"), \"manage_cookies\": _(\"Manage cookies\"), \"accept_all_config\": _(\"Accept all\"), \"reject_all_config\": _(\"Reject all\"), \"save_preferences\": _(\"Save preferences\"), \"save_and_close\": _(\"Save and close\"), \"close\": _(\"Close\"), },","title":"Button texts"},{"location":"customization/#styling","text":"The modal dialog uses the fonts of the website. Colors can be modified by CSS custom properties: body { --cc-primary: #007bff; --cc-light-gray: #ccc; --cc-dark-gray: #343a40; --cc-light: #fff; --cc-backdrop: rgba(0, 0, 0, 0.5); } All essential elements have CSS classes with cc- prefix, and you can overwrite some of their properties. If you are using a CSS framework like Bootstrap or TailwindCSS, you can set the extra CSS classes for particular elements in the styling section of COOKIE_CONSENT_SETTINGS : \"styling\": { \"primary_button_css_classes\": \"\", \"secondary_button_css_classes\": \"\", \"provider_list_css_classes\": \"\", \"provider_item_css_classes\": \"\", \"link_css_classes\": \"\", \"section_anchor_css_classes\": \"\", }, If you can't implement what you need with the methods above, instead you can create a custom CSS file and link to it. And of that is still not an option for you, you can also overwrite the templates.","title":"Styling"},{"location":"customization/#templates","text":"The templates used for the cookie consent management can be copied to the templates directory of the project and overwritten. Mostly necessary templates are these: gdpr_cookie_consent/descriptions/what_are_cookies.html is the description of the cookies in the modal dialog and cookie management page. gdpr_cookie_consent/descriptions/extra.html is the extra HTML going at the bottom of cookie management page. gdpr_cookie_consent/modal_dialog.html is the template for the cookie consent's modal dialog. gdpr_cookie_consent/cookies_management.html is the template for the external page.","title":"Templates"},{"location":"customization/#passing-variables-to-cookie-consent-management-templates","text":"If you don't want to hardcode some variables like API keys in the conditional HTML files, you can pass them in extra_context section of COOKIE_CONSENT_SETTINGS : \"extra_context\": { \"GOOGLE_ANALYTICS_TRACKING_ID\": get_secret(\"GOOGLE_ANALYTICS_TRACKING_ID\"), \"STRIPE_PUBLISHABLE_KEY\": get_secret(\"STRIPE_PUBLISHABLE_KEY\"), }, In this example, get_secret() should be a function implemented by you, that reads the secret values from the environment variables, unversioned secrets.json file, or elsewhere. The variables mentioned in extra_context will be passed to all templates of Django GDPR Cookie Consent.","title":"Passing Variables to Cookie Consent Management Templates"},{"location":"customization/#conditional-rendering-in-templates","text":"Enable gdpr_cookie_consent context processor in the template settings: TEMPLATES = [ { # \u2026 \"OPTIONS\": { \"context_processors\": [ # \u2026 \"gdpr_cookie_consent.context_processors.gdpr_cookie_consent\", ], }, }, ] Now you can check if a section was chosen by the visitor in any template by this: {% if \"functionality\" in cookie_consent_controller.checked_sections %} {% endif %} Note that this conditional rendering will happen only after page reload, not just after closing the Cookie Consent modal dialog.","title":"Conditional Rendering in Templates"},{"location":"customization/#conditional-rendering-in-javascript","text":"If you are using ReactJS, Vue, AngularJS, or other frontend library to render HTML, you can check if a cookie section was chosen by the following technique. At first set a global variable in conditional templates: {# conditional_html/functionality.html #} Then check for that value in some rendering functions: // some javascript file if (window.ENABLE_YOUTUBE_EMBEDS) { embed_youtube_videos(); }","title":"Conditional Rendering in JavaScript"},{"location":"customization/#using-content-security-policy-with-django-csp","text":"Django GDPR Cookie Consent is compatible with Content-Security-Policy via Django-CSP app. To use it together, you just need to do two things. In the project's settings, enable nonces: CSP_INCLUDE_NONCE_IN = [\"script-src\", \"style-src\"] In the conditional html snippets, set nonces for inline ","title":"Using Content-Security-Policy with Django-CSP"},{"location":"getting-started/","text":"Getting Started How to Install 1. Download and install the package with pip Get Django GDPR Cookie Consent from Gumroad . Create a directory private_wheels/ in your project's repository and add the wheel file of the app there. Link to this file in your requirements.txt : Django==5.0 file:./private_wheels/django_gdpr_cookie_consent-2.2.0-py2.py3-none-any.whl Install the pip requirements from the requirements.txt file into your project's virtual environment: (venv)$ pip install -r requirements.txt Alternatively to start quickly, install the wheel file into your Django project's virtual environment right from the shell: (venv)$ pip install /path/to/django_gdpr_cookie_consent-2.2.0-py2.py3-none-any.whl 2. Add the app to INSTALLED_APPS of your project settings INSTALLED_APPS = [ # \u2026 \"gdpr_cookie_consent.apps.GdprCookieConsentConfig\", # \u2026 ] 3. Add path to urlpatterns from django.urls import path, include urlpatterns = [ # \u2026 path( \"cookies/\", include(\"gdpr_cookie_consent.urls\", namespace=\"cookie_consent\"), ), # \u2026 ] 4. Include the widget to your template(s) Load the CSS somewhere in the section: Include the widget just before the closing tag: {% include \"gdpr_cookie_consent/includes/cookie_consent.html\" %} Link to the cookie management view, for example, in the website's footer: {% url \"cookie_consent:cookies_management\" as cookie_management_url %} {% trans \"Manage Cookies\" %} How to Use 1. Copy, paste, and modify the cookie consent configuration Copy the example of COOKIE_CONSENT_SETTINGS to the end of your project settings, then modify it to match the cookie usage of your website. In the example above, there are four cookie sections: Essential (strictly necessary), Functionality (optional), Performance (optional), and Marketing (optional). 2. Create templates to render HTML for non-required cookies Cookies that are set conditionally based upon a visitor\u2019s choices must be rendered from conditional templates. For example, analytics providers typically instruct to place the analytics tag within the page\u2019s section. However, suppose visitors are being given a choice of whether to accept analytics cookies using Django GDPR Cookie Consent. In that case, the analytics tag that sets the analytics cookies must be rendered from conditional templates. The conditional HTML might include external or inline styles, external or inline JavaScripts, and other HTML snippets. Create templates for the snippets that will be loaded or rendered when a particular section is chosen, for example: conditional_html/functionality.html conditional_html/performance.html conditional_html/marketing.html For testing, you can add the markup like: Manage the scripts that create your Essential (strictly necessary) cookies separately, unrelated to conditional html snippets. 3. Translate your titles and descriptions If your website has more than one language, prepare the translations: Use management command makemessages to collect translatable strings into django.po files. Translate the strings to the languages you need. Then, use the management command compilemessages to compile them to django.mo files.","title":"Getting Started"},{"location":"getting-started/#getting-started","text":"","title":"Getting Started"},{"location":"getting-started/#how-to-install","text":"","title":"How to Install"},{"location":"getting-started/#1-download-and-install-the-package-with-pip","text":"Get Django GDPR Cookie Consent from Gumroad . Create a directory private_wheels/ in your project's repository and add the wheel file of the app there. Link to this file in your requirements.txt : Django==5.0 file:./private_wheels/django_gdpr_cookie_consent-2.2.0-py2.py3-none-any.whl Install the pip requirements from the requirements.txt file into your project's virtual environment: (venv)$ pip install -r requirements.txt Alternatively to start quickly, install the wheel file into your Django project's virtual environment right from the shell: (venv)$ pip install /path/to/django_gdpr_cookie_consent-2.2.0-py2.py3-none-any.whl","title":"1. Download and install the package with pip"},{"location":"getting-started/#2-add-the-app-to-installed_apps-of-your-project-settings","text":"INSTALLED_APPS = [ # \u2026 \"gdpr_cookie_consent.apps.GdprCookieConsentConfig\", # \u2026 ]","title":"2. Add the app to INSTALLED_APPS of your project settings"},{"location":"getting-started/#3-add-path-to-urlpatterns","text":"from django.urls import path, include urlpatterns = [ # \u2026 path( \"cookies/\", include(\"gdpr_cookie_consent.urls\", namespace=\"cookie_consent\"), ), # \u2026 ]","title":"3. Add path to urlpatterns"},{"location":"getting-started/#4-include-the-widget-to-your-templates","text":"Load the CSS somewhere in the section: Include the widget just before the closing tag: {% include \"gdpr_cookie_consent/includes/cookie_consent.html\" %} Link to the cookie management view, for example, in the website's footer: {% url \"cookie_consent:cookies_management\" as cookie_management_url %} {% trans \"Manage Cookies\" %} ","title":"4. Include the widget to your template(s)"},{"location":"getting-started/#how-to-use","text":"","title":"How to Use"},{"location":"getting-started/#1-copy-paste-and-modify-the-cookie-consent-configuration","text":"Copy the example of COOKIE_CONSENT_SETTINGS to the end of your project settings, then modify it to match the cookie usage of your website. In the example above, there are four cookie sections: Essential (strictly necessary), Functionality (optional), Performance (optional), and Marketing (optional).","title":"1. Copy, paste, and modify the cookie consent configuration"},{"location":"getting-started/#2-create-templates-to-render-html-for-non-required-cookies","text":"Cookies that are set conditionally based upon a visitor\u2019s choices must be rendered from conditional templates. For example, analytics providers typically instruct to place the analytics tag within the page\u2019s section. However, suppose visitors are being given a choice of whether to accept analytics cookies using Django GDPR Cookie Consent. In that case, the analytics tag that sets the analytics cookies must be rendered from conditional templates. The conditional HTML might include external or inline styles, external or inline JavaScripts, and other HTML snippets. Create templates for the snippets that will be loaded or rendered when a particular section is chosen, for example: conditional_html/functionality.html conditional_html/performance.html conditional_html/marketing.html For testing, you can add the markup like: Manage the scripts that create your Essential (strictly necessary) cookies separately, unrelated to conditional html snippets.","title":"2. Create templates to render HTML for non-required cookies"},{"location":"getting-started/#3-translate-your-titles-and-descriptions","text":"If your website has more than one language, prepare the translations: Use management command makemessages to collect translatable strings into django.po files. Translate the strings to the languages you need. Then, use the management command compilemessages to compile them to django.mo files.","title":"3. Translate your titles and descriptions"}]} \ No newline at end of file diff --git a/docs/sitemap.xml.gz b/docs/sitemap.xml.gz index 5c56659..89e4d83 100644 Binary files a/docs/sitemap.xml.gz and b/docs/sitemap.xml.gz differ diff --git a/src/getting-started.md b/src/getting-started.md index da09f74..985b751 100644 --- a/src/getting-started.md +++ b/src/getting-started.md @@ -11,7 +11,7 @@ Create a directory `private_wheels/` in your project's repository and add the wh Link to this file in your `requirements.txt`: ``` -Django==4.2 +Django==5.0 file:./private_wheels/django_gdpr_cookie_consent-2.2.0-py2.py3-none-any.whl ```