Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#28088 closed Bug (invalid)

Overriding the built-in Django form widget HTML doesn't work

Reported by: Daniel Greenfeld Owned by: nobody
Component: Documentation 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

After multiple attempts following the documentation and peering into the source code, I can't override built-in widget's HTML.

Reference documentation:

This test case pares down the problem to the barest minimum example:

https://github.com/pydanny/django-widget-override-test-case

Change History (4)

comment:1 by Florian Apolloner, 8 years ago

Resolution: invalid
Status: newclosed

Two things need changing:

Closing this since it is in the documentation (https://docs.djangoproject.com/en/1.11/ref/forms/renderers/#overriding-built-in-widget-templates):

If you use the TemplatesSetting renderer, overriding widget templates works the same as overriding any other template in your project. You can’t override built-in widget templates using the other built-in renderers.

That said we will happily take PR improving the wording.

Last edited 8 years ago by Florian Apolloner (previous) (diff)

comment:2 by Florian Apolloner, 8 years ago

Diff to the referenced project to get it working:

diff --git a/sample/settings.py b/sample/settings.py
index 354d15a..3d87369 100644
--- a/sample/settings.py
+++ b/sample/settings.py
@@ -51,11 +51,12 @@ MIDDLEWARE = [
 ]
 
 ROOT_URLCONF = 'sample.urls'
+FORM_RENDERER = 'django.forms.renderers.TemplatesSetting'
 
 TEMPLATES = [
     {
         'BACKEND': 'django.template.backends.django.DjangoTemplates',
-        'DIRS': ['django/forms/templates', 'templates'],
+        'DIRS': [BASE_DIR, 'templates'],
         'APP_DIRS': True,
         'OPTIONS': {
             'context_processors': [
Last edited 8 years ago by Florian Apolloner (previous) (diff)

comment:3 by Daniel Greenfeld, 8 years ago

Perhaps specifying that FORM_RENDERER = 'django.forms.renderers.TemplatesSetting'?

Launching TSD 1.11 this week so am swamped, but I'll see if I can get a PR in.

Version 0, edited 8 years ago by Daniel Greenfeld (next)

comment:4 by Tim Graham, 8 years ago

#28102 is an accepted ticket for the documentation clarification about the need to put the full path to the built-in widget directories in DIRS.

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