I'm trying to create a "delete account" functionality in Django. I use DeleteView
for this purpose.
The problem is that after calling this view, Django
raises:
Request Method: GET
Request URL: http://127.0.0.1:8000/profiles/delete-account/
Django Version: 1.11.7
Exception Type: TemplateDoesNotExist
Exception Value:
auth/user_confirm_delete.html
My view:
class DeleteAccount(LoginRequiredMixin,DeleteView):
model = User
def get_object(self, queryset=None):
user = self.request.user
userprofile = user.userprofile
userprofile.prepare_to_delete_account()
return user
Why it tries to render this template
and why there is no such template if it's being called?
Do you know how to fix this?
The view renders a template to confirm that you want to delete the object.
By default it generates the template name auth/user_confirm_delete.html
from the app and model name.
If you want to use another template, set template_name
.
class DeleteAccount(LoginRequiredMixin,DeleteView):
model = User
template_name = 'delete_account.html'
You must create the template, Django does not include it. There is an example in the docs that you can extend:
<form action="" method="post">{% csrf_token %}
<p>Are you sure you want to delete "{{ object }}"?</p>
<input type="submit" value="Confirm" />
</form>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With