Skip to content

Commit aee9ae6

Browse files
Update README.md
1 parent 623942b commit aee9ae6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Diff for: README.md

+34
Original file line numberDiff line numberDiff line change
@@ -674,4 +674,38 @@ https://github.com/django/django/blob/master/django/forms/widgets.py
674674
The widget templates are in:
675675
django/contrib/admin/templates/admin/widgets/
676676

677+
```
678+
settings.py:
679+
680+
INSTALLED_APPS = [
681+
...
682+
'django.forms',
683+
...
684+
]
685+
686+
FORM_RENDERER = 'django.forms.renderers.TemplatesSetting'
687+
688+
689+
myapp/widgets.py:
690+
691+
from django import forms
692+
693+
class MyCustomWidget(forms.widgets.ClearableFileInput):
694+
template_name = 'widgets/my_custom_widget.html'
695+
696+
697+
myapp/forms.py:
698+
699+
class MyModelForm(forms.ModelForm):
700+
class Meta:
701+
model = MyModel
702+
widgets = {
703+
'file': widgets.MyCustomWidget,
704+
}
705+
```
706+
707+
Create template folder and template:
708+
709+
`myapp/templates/widgets/my_custom_widget.html`
710+
677711

0 commit comments

Comments
 (0)