[Django] #28088: Overriding the built-in Django form widget HTML doesn't work

47 views
Skip to first unread message

Django

unread,
Apr 17, 2017, 2:42:42 PM4/17/17
to django-...@googlegroups.com
#28088: Overriding the built-in Django form widget HTML doesn't work
--------------------------------------------+------------------------
Reporter: Daniel Greenfeld | Owner: nobody
Type: Bug | Status: new
Component: Documentation | Version: 1.11
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------------+------------------------
After multiple attempts following the documentation and peering into the
source code, I can't override built-in widget's HTML.

Reference documentation:

* https://docs.djangoproject.com/en/1.11/ref/forms/renderers/#overriding-
built-in-widget-templates
*
https://docs.djangoproject.com/en/1.11/ref/forms/renderers/#templatessetting

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

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

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

Django

unread,
Apr 17, 2017, 3:55:09 PM4/17/17
to django-...@googlegroups.com
#28088: Overriding the built-in Django form widget HTML doesn't work
----------------------------------+--------------------------------------

Reporter: Daniel Greenfeld | Owner: nobody
Type: Bug | Status: closed
Component: Documentation | Version: 1.11
Severity: Normal | Resolution: invalid

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

* status: new => closed
* resolution: => invalid


Comment:

Two things need changing:

* Change FORM_RENDERER to TemplateSettings:
https://docs.djangoproject.com/en/1.11/ref/forms/renderers/#templatessetting
* Fix the template include paths so BASE_DIR is in there (django search
literally for django/forms/widgets…)

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.

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

Django

unread,
Apr 17, 2017, 3:56:44 PM4/17/17
to django-...@googlegroups.com
#28088: Overriding the built-in Django form widget HTML doesn't work
----------------------------------+--------------------------------------

Reporter: Daniel Greenfeld | Owner: nobody
Type: Bug | Status: closed
Component: Documentation | Version: 1.11
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------

Comment (by Florian Apolloner):

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': [
```

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

Django

unread,
Apr 17, 2017, 3:59:34 PM4/17/17
to django-...@googlegroups.com
#28088: Overriding the built-in Django form widget HTML doesn't work
----------------------------------+--------------------------------------

Reporter: Daniel Greenfeld | Owner: nobody
Type: Bug | Status: closed
Component: Documentation | Version: 1.11
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------

Comment (by Daniel Greenfeld):

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.

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

Django

unread,
Apr 20, 2017, 8:06:19 AM4/20/17
to django-...@googlegroups.com
#28088: Overriding the built-in Django form widget HTML doesn't work
----------------------------------+--------------------------------------

Reporter: Daniel Greenfeld | Owner: nobody
Type: Bug | Status: closed
Component: Documentation | Version: 1.11
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------

Comment (by Tim Graham):

#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`.

--
Ticket URL: <https://code.djangoproject.com/ticket/28088#comment:4>

Reply all
Reply to author
Forward
0 new messages