TyMaszWeb / django-cookie-law

Helps your Django project comply with the EU cookie regulations by displaying a cookie information banner until it is dismissed by the user
BSD 2-Clause "Simplified" License
140 stars 69 forks source link

Banner reappears every time a website is refreshed #59

Closed krasomil closed 2 years ago

krasomil commented 4 years ago

Hello,

I use django-cookie-law==2.0.3, Django 3.0.5 and django-classy-tags 1.0.0. I also put my banner in the following cookie_banner.html page:

<script src="{% static 'cookielaw/js/cookielaw.js' %}"></script>

<div id="CookielawBanner">
    <div class="cookie-content">
        <div class="row">
            <div class="col-lg-6">
                <div class="cookie-text">
                    <p class="ml-1 small text-gray-900">This website uses cookies to make your experience better.</p>
                </div>
            </div>

            <div class="col-lg-5">
                <div class="cookie-buttons text-right">

                    <a class="btn btn-success btn-icon-split btn-sm" href="javascript:Cookielaw.createCookielawCookie();">
                        <span class="icon text-white-50">
                            <i class="fas fa-check"></i>
                        </span>              
                        <span class="text">Ok, understood</span>
                    </a>
                </div>
            </div>
        </div>

    <div class="close-cookies  border-bottom-success"></div>
    </div>
    </div>

I also call {% load cookielaw_tags %} in my base.html. When I load the website, I get the banner and when pressing "Ok, understood" it disappears. However, after refreshing the page, it re-appears again. Do you have any idea if what is wrong here? Could it be caused by a bug in cookielaw\js\cookielaw.js?

krasomil commented 4 years ago

I fixed it by including the code on a starting page:

{% if not "cookielaw_accepted" in request.COOKIES %}
    {% include 'partials/cookie_banner.html' %}
{% endif %}

However, I'm not sure if that's how developers of django_cookie_law intended users to use it.

josylad commented 4 years ago

I fixed it by including the code on a starting page:

{% if not "cookielaw_accepted" in request.COOKIES %}
    {% include 'partials/cookie_banner.html' %}
{% endif %}

However, I'm not sure if that's how developers of django_cookie_law intended users to use it.

Thanks for this tip. I had the same issue with a custom banner html but your tip above fixed it.

piotrkilczuk commented 2 years ago

Yes, that's the only way to do this if you're not using the template tag.

piotrkilczuk commented 2 years ago

Otherwise just override the contents of the banner by placing a template under templates/cookielaw/banner.html.