Reputation: 119
I'm creating a form where data is coming from previous form and i'm storing that data in session. If user directly visits second page than I want the user to redirect to first page, but I can't find any way to do it. Is it possible?
my code(second page)
def get(self, request):
a = request.session['a']
since a is not set if user directly visits this page I want him to redirect to first page if session not found.
Upvotes: 0
Views: 555
Reputation: 73480
You can redirect the user if the key is missing in the session:
from django.shortcuts import redirect
def get(self, request):
if 'a' not in request.session:
return redirect("name_of_first_view")
# ...
Upvotes: 2