Finding the Django Templates files?

I am looking to overwrite the generic deleteview template. Maybe cope the code and change it a bit for myself.

I looked around in the source code (I read somewhere that would be the right way to learn) and ended up here:

https://github.com/django/django/blob/main/django/template/backends/django.py

There is no reference to a real template file there, only code.

Can someone point me in the better direction. Where are the original templates stored?

There are no “generic templates” for the generic CBVs. All the edit CBVs can generate a default template name, but it’s up to you to build the template itself.

That makes sense now. No wonder they were hard to find :smiley:
Is there a best practice for how to implement them “quick, safe and easy”? (thinking about model.as_view() or the like)

It depends upon which view you’re talking about - the standard DeleteView deletes a single object, so the template could be something as simple as Are you sure you want to delete {{ object.id }}? with a submit button. You could also use a ModelForm with the fields as readonly.

Create and Update views are easily implemented using a ModelForm.

In these cases you can then use {{ form.as_p }} (or whatever) in the template to render that form.

So in the “trivial” case, it’s less about the template and more about the form.

1 Like

I think on a related note I will try this one out: https://github.com/carltongibson/neapolitan