Skip to content Skip to sidebar Skip to footer

Django Forms Get Value From Cookies

How to make django forms get value from cookies? I save user previuos input to cookies and if user opens form again I want to show that values. Now I do forms manually like this: &

Solution 1:

I solved this by myself. You just need to use django forms initial attribute for your form in views.

Solution example:

if'something'in request.COOKIES:
    something = request.COOKIES['something']
else:
    something = ''


form = SomethingForm(initial={'something': something })

Post a Comment for "Django Forms Get Value From Cookies"