Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#28942 closed Bug (invalid)

ChoiceWidget.option_template_name ignores TEMPLATES DIRS

Reported by: Maksim Iakovlev Owned by: nobody
Component: Forms Version: 1.11
Severity: Normal Keywords:
Cc: 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 Maksim Iakovlev)

Django can only find template if it located in app dir (if path relative to BASE_DIR is myapp/templates/myapp/mytemplate.html), but raises TemplateDoesNotExist if template located in custom dir specified in TEMPLATES DIRS (if path relative to BASE_DIR is templates/myapp/mytemplate.html).

class MyWidget(ChoiceWidget):
    option_template_name = 'myapp/mytemplate.html'
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.join(BASE_DIR, 'templates'),
        ],
        'APP_DIRS': True,
...

Change History (3)

comment:1 by Maksim Iakovlev, 7 years ago

Description: modified (diff)

comment:2 by Tim Graham, 7 years ago

Resolution: invalid
Status: newclosed

My guess is that you aren't using FORM_RENDERER = 'django.forms.renderers.TemplatesSetting' in your settings. Read about form rendering.

If you believe that Django is at fault, please give a pointer to the faulty code.

comment:3 by Maksim Iakovlev, 7 years ago

You right, I didn't know that default renderer "... loads templates first from the built-in form templates directory in django/forms/templates and then from the installed apps’ templates directories using the app_directories loader" and doesn't use TEMPLATES setting. Thank you for the answer.

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