Python Forum
How to Prevent Double Submission in Django
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Prevent Double Submission in Django
#1
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
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})
Reply


Messages In This Thread
How to Prevent Double Submission in Django - by mactron - Jul-14-2023, 12:29 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Automating Captcha form submission with Mechanize Dexty 2 3,466 Aug-03-2021, 01:02 PM
Last Post: Dexty
  prevent getting blocked maneesh7787 3 2,472 Dec-11-2019, 08:41 AM
Last Post: buran
  Django: How to automatically substitute a variable in the admin page at Django 1.11? m0ntecr1st0 3 3,529 Jun-30-2019, 12:21 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020