[Django] #33688: DjangoTemplates app_dirname does not apply to app directories

9 views
Skip to first unread message

Django

unread,
May 9, 2022, 7:12:45 AM5/9/22
to django-...@googlegroups.com
#33688: DjangoTemplates app_dirname does not apply to app directories
-----------------------------------------+---------------------------
Reporter: Dutcher | Owner: nobody
Type: New feature | Status: new
Component: Uncategorized | Version: 4.0
Severity: Normal | Keywords: Templates
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+---------------------------
Each backend defines a conventional name for the subdirectory inside
applications where its templates should be stored
https://docs.djangoproject.com/en/4.0/topics/templates/#configuration

The DjangoTemplates class allows for adjusting the name of the folder in
which templates are found, but the template loaders do not take this into
account. In particular the App Directory Template Loader the folder name
("textures" is currently hardcoded and immutable without writing a custom
loader. I think it's better if the code allows for setting the folder name
as input upon instance creation:

template/loaders/app_directories.py
{{{
from .filesystem import Loader as FilesystemLoader

class Loader(FilesystemLoader):
def __init__(self, engine, dir_name=None):
self.dir_name = dir_name or "templates"
super(Loader).__init__(engine)

def get_dirs(self):
return get_app_template_dirs(self.dir_name)
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33688>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 9, 2022, 8:20:16 AM5/9/22
to django-...@googlegroups.com
#33688: DjangoTemplates app_dirname does not apply to app directories
-------------------------------+--------------------------------------
Reporter: Dutcher | Owner: Dutcher
Type: New feature | Status: assigned
Component: Uncategorized | Version: 4.0
Severity: Normal | Resolution:

Keywords: Templates | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Dutcher):

* owner: nobody => Dutcher
* status: new => assigned


Old description:

> Each backend defines a conventional name for the subdirectory inside
> applications where its templates should be stored
> https://docs.djangoproject.com/en/4.0/topics/templates/#configuration
>
> The DjangoTemplates class allows for adjusting the name of the folder in
> which templates are found, but the template loaders do not take this into
> account. In particular the App Directory Template Loader the folder name
> ("textures" is currently hardcoded and immutable without writing a custom
> loader. I think it's better if the code allows for setting the folder
> name as input upon instance creation:
>
> template/loaders/app_directories.py
> {{{
> from .filesystem import Loader as FilesystemLoader
>
> class Loader(FilesystemLoader):
> def __init__(self, engine, dir_name=None):
> self.dir_name = dir_name or "templates"
> super(Loader).__init__(engine)
>
> def get_dirs(self):
> return get_app_template_dirs(self.dir_name)
> }}}

New description:

Each backend defines a conventional name for the subdirectory inside
applications where its templates should be stored
https://docs.djangoproject.com/en/4.0/topics/templates/#configuration

The DjangoTemplates class allows for adjusting the name of the folder in
which templates are found, but the template loaders do not take this into
account. In particular the App Directory Template Loader the folder name
("textures" is currently hardcoded and immutable without writing a custom
loader. I think it's better if the code allows for setting the folder name
as input upon instance creation:

template/loaders/app_directories.py
{{{
from .filesystem import Loader as FilesystemLoader

class Loader(FilesystemLoader):
def __init__(self, engine, dir_name=None):
self.dir_name = dir_name or "templates"
super(Loader).__init__(engine)

def get_dirs(self):
return get_app_template_dirs(self.dir_name)
}}}


Edit: PR availlable: https://github.com/django/django/pull/15676
It is my first PR on django, so feedback is welcome :)

--

--
Ticket URL: <https://code.djangoproject.com/ticket/33688#comment:1>

Django

unread,
May 9, 2022, 9:43:06 AM5/9/22
to django-...@googlegroups.com
#33688: DjangoTemplates app_dirname does not apply to app directories
-------------------------------+--------------------------------------
Reporter: Dutcher | Owner: Dutcher
Type: New feature | Status: assigned
Component: Uncategorized | Version: 4.0
Severity: Normal | Resolution:
Keywords: Templates | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Dutcher):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/33688#comment:2>

Django

unread,
May 9, 2022, 11:44:49 AM5/9/22
to django-...@googlegroups.com
#33688: DjangoTemplates app_dirname does not apply to app directories
---------------------------------+--------------------------------------
Reporter: Dutcher | Owner: Dutcher
Type: New feature | Status: closed
Component: Template system | Version: 4.0
Severity: Normal | Resolution: wontfix

Keywords: Templates | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* status: assigned => closed
* resolution: => wontfix
* component: Uncategorized => Template system


Comment:

Thanks for this ticket, however it looks quite niche and not worth
maintaining by Django itself. Creating a small custom loader seems
justified in you cannot keep templates in the `templates` directory.

Please first start a discussion on the DevelopersMailingList (if you don't
agree), where you'll reach a wider audience and see what other think, and
[https://docs.djangoproject.com/en/stable/internals/contributing/bugs-and-
features/#requesting-features follow the guidelines with regards to
requesting features].

--
Ticket URL: <https://code.djangoproject.com/ticket/33688#comment:3>

Reply all
Reply to author
Forward
0 new messages