I have a view function for login which blocks user after 3 unsuccessful login attempts
the function is as follows
def my_login(request):
context = {}
if request.method == 'POST':
form = LoginForm(request.POST)
user_id = form.cleaned_data['user_id']
user_password = form.cleaned_data['password1']
if form.is_valid:
try:
usr = Users.objects.get(pk=user_id)
except:
context['form'] = form
context['msg'] = "User Not Found"
return render(request, 'login.html', context)
'''
## code for blocking
'''
if user_password == usr.password1:
usr.login_attempt = 0
usr.save()
login(usr)
return redirect('dashbord')
else:
usr.login_attempt += 1
usr.save()
context['msg'] = f"Attempts tried { str(usr.login_attempt)}"
form = LoginForm()
context['form'] = form
return render(request, 'login.html', context)
The problem here is when I entered wrong password it is rendering to login page but when I click on reload the form is again re submitting and the login_attempt getting updated
I don't want this kind of behavior so how can I stop form resubmitting on clicking reload
one possible solution I assumed is by manipulating the request object in the view like request = HttpRequest()
but it is failing at csrf validation. is there any possibilities to overcome this issue