Sometime we might came across the need to redirect to another url from django template. Like if you want to check if user is authenticated or not. So following is the example for doing that in Django.
def dispatch(self, request, *args, **kwargs):
if not request.user.is_authenticated():
return redirect('login')
return super(MyTemplateView, self).dispatch(request, *args, **kwargs)
I was new to Django and didn't know how can I redirect to another page depending on the specific condition in Django but this helped a lot!
Thanks @aamishbaloch