I would like to put a redirect command inside of a function and then call this function in a Django view. Can anyone give me a hint why my code below does not redirect?
This redirection works:
views.py
from django.shortcuts import redirect from django.http import HttpResponse def my_view(request): return redirect("https://stackoverflow.com") return HttpResponse("<p>redirection did not work</p>") This redirection does not work:
views.py
from django.shortcuts import redirect from django.http import HttpResponse # define subfunction def test(): return redirect("https://stackoverflow.com") def my_view(request): test() return HttpResponse("<p>redirection did not work</p>")
redirectshortcut function returns a subclass ofHttpResponse