figuring out bug with django cookies: not working on server

14 views
Skip to first unread message

Samuel Muiruri

unread,
Oct 2, 2017, 1:34:54 PM10/2/17
to Django users

I have a site that relies on checking if a cookie exists for service_id and if it does checks if you can upload files for service... this works nicely offline but on pushing changes to server it created a bug where even though the cookie can be seen (on the dev console)

enter image description here

and I assign the cookie to a context variable which ends up saying None even though I can see the cookie from the dev console.

class PictureCreateView(CreateView):
    model = Picture
    fields = "__all__"
    template_name = 'accounts/upload-file.html'

    def get_context_data(self, **kwargs):

        context = super(PictureCreateView, self).get_context_data(**kwargs)
        context['service_id'] = self.request.COOKIES.get('service_id', None)

        return context

on the template

{% if service_id %}
    #display form
{% else %}
    Sorry it seems you're missing some vital data needed before ...
{% endif %}

any ideas?

here's a screen record (local & live): https://youtu.be/aud59Avp1aI

ADEWALE ADISA

unread,
Oct 2, 2017, 6:06:24 PM10/2/17
to django...@googlegroups.com

can you show the code where you set the cookie before retrieving it

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/fd1f686b-dded-4aaa-8f6b-274419afa0a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Samuel Muiruri

unread,
Oct 2, 2017, 6:14:55 PM10/2/17
to django...@googlegroups.com
@login_required
def edit_service(request, service_id, template_name="edit-service.html"):
context = RequestContext(request)

context['service_id'] = request.COOKIES.get('service_id', None)

...

response = render_to_response(template_name, context)
response.set_cookie('service_id', service_id)

return response

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/mSWmg0HVxz0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.



--
Best Regards,
Samuel Muiruri.
Web Designer | +254 738 940064
Reply all
Reply to author
Forward
0 new messages