Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DJANGO: TemplateDoesNotExist: auth/user_confirm_delete.html

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?

like image 543
Milano Avatar asked Mar 08 '23 07:03

Milano


1 Answers

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>
like image 184
Alasdair Avatar answered Mar 11 '23 08:03

Alasdair