[Answer]-Cookie should be constructed first

1๐Ÿ‘

โœ…

You need to write a custom decorator to handle the situation.

You can read more about Decorators here: https://docs.djangoproject.com/en/dev/topics/http/decorators/

For example the csrf_exempt decorator allows a request to be processed without the csrf token facility in forms, very useful for JSON based requests.

@csrf_exempt
def new(request):
    if request.method == 'POST':
        json_data = simplejson.loads(request.raw_post_data)
        try:

Similarly have a custom decorator for ensuring cooking and use it as:

@ensure_cookie
def new(request):
...

Writing custom decorators: How to write a custom decorator in django?

๐Ÿ‘คredDragonzz

0๐Ÿ‘

You can put this code in process_request or process_view method in custom middleware.

๐Ÿ‘คkobuz

Leave a comment