1👍
This sounds like you have a long running process, and the user gets tired of waiting, clicks on “stop” in the browser; the other scenario is – user opens another tab and sends the same request again.
A few ways to solve this problem.
-
Use the transaction middleware to prevent your db objects from being corrupted if the request is interrupted.
-
Use a task queue like celery. At the first request, offload your task to the queue/broker. Send the user a message that their request has been accepted for processing. Now the user is free to send a duplicate request. If they do, you can check what is the status of the queue and reject the duplicate requests.
Source:stackexchange.com