Home > OS >  django.template.exceptions.TemplateDoesNotExist: documents/project_confirm_delete.html
django.template.exceptions.TemplateDoesNotExist: documents/project_confirm_delete.html

Time:12-04

I used Django 3.2.9 and used a class in order to delete a project. Here is my code.

from django.views.generic.edit import CreateView, DeleteView, UpdateView

class ProjectDeleteView(DeleteView):
    http_method_names = ['get']
    model = Project
    pk_url_kwarg = "pk"

    def get_success_url(self):
        return reverse("documents:draftdocumentview")

When I called it said like this;

django.template.exceptions.TemplateDoesNotExist: documents/project_confirm_delete.html

I am not sure about the project_confirm_delete.html. Should I make the html file? Or it is supported from Django Template?

CodePudding user response:

You have to create a templates folder inside the app, and then create another folder same as app name inside the templates then create project_confirm_delete.html inside that.

Something like this:

documents
        ----templates
        -------------documents
        ----------------------project_confirm_delete.html

Now, inside the project_confirm_delete.html file you need a form; assuming you are using crispy and blocks, it should look like this:

{% extends 'design/base.html' %}
{% load crispy_forms_tags %}
{% block content %}
<h1>Deleting File, Are You Sure?</h1>   
        <div class="media-body">
            <form method="POST" enctype="multipart/form-data">
                {% csrf_token %}
                <fieldset class="form-group">
                    
                    {{ form|crispy }}               
                </fieldset>
                <div>
                    <button type="submit">Yes Delete</button>
                </div>  
            </form>
        </div>        

{% endblock content %}

CodePudding user response:

When I created a function and called it, it worked well. Here is the code.

def ProjectDelete(request,pk):
    #project_id = request.GET.get('pk')
    project = Project.objects.filter(id=pk)
    project.delete()
    return redirect(reverse("documents:draftdocumentview"))
  • Related