redirect authenticated user in CreateView

289 views
Skip to first unread message

saeed albooyeh

unread,
Sep 25, 2019, 1:09:52 PM9/25/19
to Django users
hi
i used CreateView for registration in my project and i wanna prevent authenticated user from accessing to the register url and redirect it to another page
can anyone tell me how can i do it?

Randy Hughes

unread,
Sep 25, 2019, 2:36:37 PM9/25/19
to django...@googlegroups.com
from django.shortcuts import HttpResponseRedirect


class ExampleView(TemplateView):
template_name = 'pages/example.html'

def get(self, request):
if not request.user.is_authenticated:
return HttpResponseRedirect('login')

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/53f16488-e8d6-4992-8446-99a857e5dd5b%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages