36
Yeah, return redirect('http://stackoverflow.com/')
is the correct method.
If you do the following, you can confirm that is a working method to redirect.
from django.shortcuts import redirect
def optout(request):
return redirect("http://stackoverflow.com/")
Your conditional statements must not be catching.
18
using class HttpResponseRedirect
from django.http import HttpResponseRedirect
def out(request):
return HttpResponseRedirect("http://google.com")
Or:
using class HttpResponse
from django.http import HttpResponse
def out(request):
response = HttpResponse("", status=302)
response['Location'] = "scheme://host"
return response
NOTE:
The last one is useful to redirect from a website to a mobile
(Android/Iphone) app. Where location isscheme://host
- [Django]-Having Django serve downloadable files
- [Django]-Django admin and MongoDB, possible at all?
- [Django]-Add a non-model field on a ModelSerializer in DRF 3
Source:stackexchange.com