Django Redirect Not Working

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Django Redirect Not Working

göktürk sığırtmaç
Hello, my UserCreate class is create user via CreateAPIView. I want to check. if user is auth, auth user directly to 'profile' URI. 

class UserCreate(generics.CreateAPIView):

serializer_class = UserCreateSerializer
permission_classes = (~IsAuthenticated,)
queryset = User.objects.all()

def __init__(self):
if IsAuthenticated:
print("hello")
redirect("profile/")

code above is working print method but not working redirect method.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d9369cce-3734-4bff-ac53-ce785918362b%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Django Redirect Not Working

Aldian Fazrihady
If that API is accessed via AJAX, then your JS code needs translate status 302 and Location header to JS code that sets "location.href"

Regards,

Aldian Fazrihady
http://aldianfazrihady.com

On Sat, 24 Aug 2019, 17:49 göktürk sığırtmaç, <[hidden email]> wrote:
Hello, my UserCreate class is create user via CreateAPIView. I want to check. if user is auth, auth user directly to 'profile' URI. 

class UserCreate(generics.CreateAPIView):

serializer_class = UserCreateSerializer
permission_classes = (~IsAuthenticated,)
queryset = User.objects.all()

def __init__(self):
if IsAuthenticated:
print("hello")
redirect("profile/")

code above is working print method but not working redirect method.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d9369cce-3734-4bff-ac53-ce785918362b%40googlegroups.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAN7EoAZfY%2B%3D9_Qk%2BGC2vmCaAj_STxRqM4Hf832cEWEySi6WN0w%40mail.gmail.com.