1

I have a view like below.

class ConfirmationPageView(generic.TemplateView):
    template_name = "confirmation.html"

What I want is to immediately move onto the below view once the ConfirmationPageView is loaded (which means its templates were loaded too).

class SecondPageView(generic.TemplateView):
    template_name = "second.html"

I don't care if the user can't see the ConfirmationPageView in this very short transition. I just need this confirmation page to show up breifly so that a third party analytics application can track whether a user visited this confirmation page. Thank you, and please leave any questions in the comments.

coderDcoder
  • 585
  • 3
  • 16
  • This change might be more suited to be done through javascript, as once the template is rendered the views don't have any control of what happens next – Brian Destura Sep 20 '22 at 02:03

1 Answers1

0

You can use the Django redirect function.

from django.shortcuts import redirect

def view_to_redirect_to(request):
    #This could be the view that handles the display of created objects"
    ....
    perform action here
    return render(request, template, context)

def my_view(request):
    ....
    perform form action here
    return redirect(view_to_redirect_to)

This is an example of it in use. Here is a link to a similar post. How to redirect from a view to another view In Django

Messi10
  • 1
  • 2