Add a Cancel Button to Django Delete Confirm Template

Django’s class based DeleteView directs the user to a confirm page before the item is deleted. If the user decides they do not want to delete, they can cancel it by clicking the back button on the browser. Pretty simple. Reinforces the meaning of the back button.

Some of my customers disagree with that line of thinking. When some users accidentally end up on the delete confirm page, they panic. They probably are not even thinking of using the back button. Moreover, they might not be confident that the back button does not do a delete before going back. A “Cancel” button is what they really want.

How to implement it with minimal hacking? The answer is almost too simple: add a Cancel button and have it’s onclick method issue a back command. Here is a Bootstrap template that does that:

<form action="" method="post">
    <p>Are you sure you want to delete the item?</p>
    <input class="btn btn-primary" type="submit" value="Confirm"/>
    <button onclick="window.history.back();" class="btn btn-default" type="button">Cancel</button>

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s