This is my first web development project. It is basically an e-voting website. The index page is the login page. So, when the user login using valid credentials, the website will take the user to the voting page where that contains a voting form and some other options like feedback, news updates, etc. in the Navigation bar. The login request is "POST". The vote submission request is also "POST". Here, if the user presses other option like submitting feedback or viewing the candidates, will take the user to that respective pages. And if the user presses the back button, the website should take him to the voting page again where he can again use other facilities voting, viewing candidates, or submit feedback. But the problem I face is if the user presses the back button from the 3rd page i.e., feedback page or viewing candidates page, it shows an error "Confirm Form Resubmission". Help me fix this bug. Thank You in advance.
views.py
from django.shortcuts import render,redirect
from django.contrib.auth.models import User, auth
from django.contrib import messages
from .models import voteoption,receive,received_feedback,updates
# Create your views here.
def index(request):
return render(request,"index.html")
def login(request):
if request.method == 'POST':
username = request.POST['username']
password = request.POST['password']
user = auth.authenticate(username=username,password=password)
if user is not None:
auth.login(request, user)
cand = voteoption.objects.all()
return render(request,"votepage.html", {'candidates': cand})
else:
messages.info(request,'Invalid Email or Password')
return render(request,'index.html')
else:
return render(request,'index.html')
def logout(request):
auth.logout(request)
return redirect("/")
def update(request):
news = updates.objects.all()
return render(request,'updates.html', {'upd': news})
def contact(request):
return render(request,'contact.html')
def feedback(request):
return render(request,'feedback.html')
def feedbacksubmit(request):
feedback = request.POST['feedback']
data = received_feedback(response=feedback)
data.save()
messages.info(request,'Feedback Submitted Successfully')
return render(request,'submitted.html')
def candidates(request):
cand = voteoption.objects.all()
return render(request,'candidates.html',{'candidates': cand} )
def submitvote(request):
reg_no = request.POST['reg_no']
selection = request.POST['selection']
voter = request.POST['voter']
if receive.objects.filter(mail=voter).exists():
messages.info(request,'You have already Voted')
return render(request,'submitted.html')
else:
data = receive(reg_no=reg_no,selection=selection,mail=voter)
data.save()
messages.info(request,'You have voted Successfully. Thank You!')
return render(request,'submitted.html')
What changes should I make?
Since this is my first project, there might be a lot of poor coding techniques. So, please suggest me with better codes where I should replace in my code even though if it is not related to this bug.