Opened 42 hours ago

Closed 40 hours ago

#35966 closed New feature (wontfix)

Support `check` for invalid `template_name` string in `TemplateView` and other related types

Reported by: Sobolev Nikita Owned by:
Component: Core (System checks) Version: 5.1
Severity: Normal Keywords: checks, views, template_name
Cc: Sobolev Nikita Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Sobolev Nikita)

python manage.py check helps us to find a lot of problems before actually running the project itself / tests for it.

I think that one thing that we can also check statically is template_name strings in different views that we have set-up in urls.
These templates can be found using regular Django machinery and help finging issues sooner.

Basically, I expect:

from django.views.generic import TemplateView

class MyView(TemplateView):
     template_name = 'my.html'

to raise an error during python manage.py check if my.html cannot be found with TEMPLATE loader settings. When MyView is present in urls.py as:

urlpatterns = [
    path('/whatever', MyView.as_view(), name='whatever'),
]

What do others think?

Change History (2)

comment:1 by Sobolev Nikita, 42 hours ago

Description: modified (diff)

comment:2 by Sarah Boyce, 40 hours ago

Component: Core (Management commands)Core (System checks)
Resolution: wontfix
Status: newclosed

Hi Sobolev, thank you for the ticket
Before we accept new features for Django, we first want to see this being discussed with the broader community to check we're all aligned for the addition.
Could you start a new conversation on the Django Forum? You'll reach a broader audience and receive additional feedback

I'll close the ticket for now, but if the community agrees with the proposal, please return to this ticket and reference the forum discussion so we can re-open it.
For more information, please refer to the documented guidelines for requesting features.

---

In terms of my thoughts... This would be for anything that inherits from TemplateResponseMixin. People can define their own get_template_names method (this either raises a ImproperlyConfigured error or returns a list of template names). Note that you can also have template_name as an init kwarg like MyView.as_view(template_name="my.html"). So in short, it might not be as simple as it seems, hence I'd like to see a bunch of people saying they'd find this useful 👍

Note: See TracTickets for help on using tickets.
Back to Top