Django - @login_required decorator while passing arguments with form POST

464 Views Asked by At

I am passing a variable from template to view with form POST method. And view uses @login_required decorator as it is needed. If user is not logged in it goes login page and come backs to the view again but the passed variable information was not there anymore. Is there any way to solve this? I found a old stackoverflow post here but it's not working for me. Below is my view function

@login_required
def become_booster(request):
    if request.method == "POST" 
        email = request.POST.get('email')
        user = CustomUser.objects.get(email= email)
        tiers = Tiers.objects.filter(user=user)
        form = SubscriptionForm
        return render(request,'select_tier.html',{'tiers':tiers,'form':form,'creator':user})
1

There are 1 best solutions below

0
sreekanthkura7 On BEST ANSWER

Instead of form POST, I am sending user info with url and my issue was resolved.

@login_required
def become_booster(request,email):
    user = CustomUser.objects.get(email= email)
    tiers = Tiers.objects.filter(user=user)
    form = SubscriptionForm
    return render(request,'select_tier.html',{'tiers':tiers,'form':form,'creator':user})