1

I've seen this Q&A:

Django DeleteView without confirmation template

and this one:

Django CSRF token won't show

but that doesn't address the built-in intended functionality of the DeleteViewm CBV when issued a GET. From the docs (emphasis mine):

https://docs.djangoproject.com/en/2.1/ref/class-based-views/generic-editing/#django.views.generic.edit.DeleteView

"If this view is fetched via GET, it will display a confirmation page that should contain a form that POSTs to the same URL."

The problem is that as I understand it, the rendered template in response to a GET will not included the RequestContext necessary to include the {% csrf_token %} in the mentioned POST form. I worked around it for the time being by overriding the get() method so that it uses render() to return the page, since it automatically includes the appropriate context.

How do I maximally leverage the DeleteView? What am I doing wrong that I need to implement the following code in my view?

def get(self, request, *args, **kwargs):
    self.object = self.get_object()
    context = self.get_context_data(object=self.object)
    return render(self.request,'mainapp/template_confirm_delete.html')
Brian
  • 642
  • 7
  • 18

0 Answers0