Answer the question
In order to leave comments, you need to log in
How to do redirect after sending response?
There is a view that receives a parameter, you need to check if this parameter is in the cookie:
a) redirect
b) if not, then add to cookies and redirect ... How to combine a redirect and sending a response ...
def redirect_to_basic_url(request, arg_one):
obj = get_object_or_404(Model, model_param=arg_one)
if str(arg_one) in str(request.COOKIES.get('cookie_name')):
return redirect(obj.PARAM)
else:
context = {'short_cookie': str(request.COOKIES.get('cookie_name'))}
context['short_cookie'] += ' | ' + str(arg_one)
response = render(request, 'template.html', context)
response.set_cookie('cookie_name', context['short_cookie'])
return response #and redirect(obj.PARAM)
Answer the question
In order to leave comments, you need to log in
response = redirect(obj.PARAM)
response.set_cookie('cookie_name', context['short_cookie'])
return response
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question