I would like to prevent double submission in Django. The problem arises when the user clicks on the back button in the browser. I know that I can use JavaScript, but I would like to fix the issue using Python.
I also attempted to resolve the issue by using HttpResponseRedirect, but it did not resolve the problem. Any suggestions would be greatly appreciated. Thank you!
Here is the code:
views.py
I also attempted to resolve the issue by using HttpResponseRedirect, but it did not resolve the problem. Any suggestions would be greatly appreciated. Thank you!
Here is the code:
views.py
class HandleChannelFormView(FormView):
template_name = 'details.html'
template_added = "success.html"
form_class = MediaForm
success_url = reverse_lazy('data')
def form_valid(self, form):
data = self.request.session.get('data', None)
if not data:
messages.error(self.request, 'No channel data found in session.')
else:
category_id = form.cleaned_data['category'].id if form.cleaned_data['category'] else None
language_id = form.cleaned_data['language'].id if form.cleaned_data['language'] else None
data.update({
'body': form.cleaned_data['body'],
'category_id': category_id,
'category_name': form.cleaned_data['category'].name if form.cleaned_data['category'] else None,
'language_id': language_id,
'nsfw': form.cleaned_data['nsfw'], # Add the nsfw value to the data dictionary
})
counter = self.request.session.get('counter', {})
StoreChannelData.save_data(data, counter)
return render(self.request, self.template_added, {'data': data, 'media_form': form})
