Issues with deleting cookie in Django

Viewed 29

I am having an issue deleting a HubSpot cookie in Django. I have a landing page with a form, and we were at a Trade Show capturing leads and since all leads used my computer and the hubspotutk cookie tracking user id was added, all new leads coming in were 'reconversions' instead of new contacts.

I am attempting to simply delete the COOKIE on page load if it is there so the hubspotutk cookie gets reset on every refresh of the page, but it appears the cookie is never actually removed although it is there.

Unfortunately with the code below I get an infinite redirect, only assuming that the hubspotutk cookie is not deleted as expected. Can anyone show me what I am doing wrong?


def request_demo_landing(request):

    if request.COOKIES.get('hubspotutk'):
        response = HttpResponseRedirect('site.com/request-demo-landing/')
        response.delete_cookie('hubspotutk')
        return response

    ...

I have also tried just updating the value to something random with Faker and that also doesn't work, it provides 2 keys that are the same in the dev console.

faker = Faker()
response.set_cookie(key='hubspotutk', value=f'{faker.numerify("###############")}')
return response
0 Answers
Related