@@ -34,12 +34,12 @@ You can get Django Widget Tweaks by using pip::
3434 $ pip install django-widget-tweaks
3535
3636To enable `widget_tweaks ` in your project you need to add it to `INSTALLED_APPS ` in your projects
37- `settings.py ` file::
37+ `settings.py ` file:
3838
39- INSTALLED_APPS = [
40- ...
39+ .. code-block :: python
40+
41+ INSTALLED_APPS += [
4142 ' widget_tweaks' ,
42- ...
4343 ]
4444
4545 Usage
@@ -65,7 +65,9 @@ This is a template tag that can be used as an alternative to aforementioned
6565filters. This template tag renders a field using a syntax similar to plain
6666HTML attributes.
6767
68- Example::
68+ Example:
69+
70+ .. code-block :: html+django
6971
7072 {% load widget_tweaks %}
7173
@@ -87,7 +89,9 @@ Example::
8789
8890For fields rendered with ``{% render_field %} `` tag it is possible
8991to set error class and required fields class by using
90- ``WIDGET_ERROR_CLASS `` and ``WIDGET_REQUIRED_CLASS `` template variables::
92+ ``WIDGET_ERROR_CLASS `` and ``WIDGET_REQUIRED_CLASS `` template variables:
93+
94+ .. code-block :: html+django
9195
9296 {% with WIDGET_ERROR_CLASS='my_error' WIDGET_REQUIRED_CLASS='my_required' %}
9397 {% render_field form.field1 %}
104108----
105109Adds or replaces any single html attribute for the form field.
106110
107- Examples::
111+ Examples:
112+
113+ .. code-block :: html+django
108114
109115 {% load widget_tweaks %}
110116
@@ -128,7 +134,9 @@ add_class
128134Adds CSS class to field element. Split classes by whitespace in order to add
129135several classes at once.
130136
131- Example::
137+ Example:
138+
139+ .. code-block :: html+django
132140
133141 {% load widget_tweaks %}
134142
@@ -142,7 +150,9 @@ Sets HTML5 data attribute ( http://ejohn.org/blog/html-5-data-attributes/ ).
142150Useful for unobtrusive javascript. It is just a shortcut for 'attr' filter
143151that prepends attribute names with 'data-' string.
144152
145- Example::
153+ Example:
154+
155+ .. code-block :: html+django
146156
147157 {% load widget_tweaks %}
148158
@@ -154,7 +164,9 @@ append_attr
154164
155165Appends attribute value with extra data.
156166
157- Example::
167+ Example:
168+
169+ .. code-block :: html+django
158170
159171 {% load widget_tweaks %}
160172
@@ -169,7 +181,9 @@ remove_attr
169181-----------
170182Removes any single html attribute for the form field.
171183
172- Example::
184+ Example:
185+
186+ .. code-block :: html+django
173187
174188 {% load widget_tweaks %}
175189
@@ -182,7 +196,9 @@ add_label_class
182196
183197The same as `add_class ` but adds css class to form labels.
184198
185- Example::
199+ Example:
200+
201+ .. code-block :: html+django
186202
187203 {% load widget_tweaks %}
188204
@@ -196,7 +212,9 @@ add_error_class
196212The same as 'add_class' but adds css class only if validation failed for
197213the field (field.errors is not empty).
198214
199- Example::
215+ Example:
216+
217+ .. code-block :: html+django
200218
201219 {% load widget_tweaks %}
202220
@@ -209,7 +227,9 @@ add_error_attr
209227
210228The same as 'attr' but sets an attribute only if validation failed for
211229the field (field.errors is not empty). This can be useful when dealing
212- with accessibility::
230+ with accessibility:
231+
232+ .. code-block :: html+django
213233
214234 {% load widget_tweaks %}
215235
@@ -221,7 +241,9 @@ add_required_class
221241
222242The same as 'add_error_class' adds css class only for required field.
223243
224- Example::
244+ Example:
245+
246+ .. code-block :: html+django
225247
226248 {% load widget_tweaks %}
227249
@@ -235,15 +257,19 @@ field_type and widget_type
235257``'field_type' `` and ``'widget_type' `` are template filters that return
236258field class name and field widget class name (in lower case).
237259
238- Example::
260+ Example:
261+
262+ .. code-block :: html+django
239263
240264 {% load widget_tweaks %}
241265
242266 <div class="field {{ field|field_type }} {{ field|widget_type }} {{ field.html_name }}">
243267 {{ field }}
244268 </div>
245269
246- Output::
270+ Output:
271+
272+ .. code-block :: html+django
247273
248274 <div class="field charfield textinput name">
249275 <input id="id_name" type="text" name="name" maxlength="100" />
@@ -255,12 +281,16 @@ Mixing render_field and filters
255281
256282The render_field tag and filters mentioned above can be mixed.
257283
258- Example::
284+ Example:
285+
286+ .. code-block :: html+django
259287
260288 {% render_field form.category|append_attr:"readonly:readonly" type="text" placeholder="Category" %}
261289
262290
263- returns::
291+ returns:
292+
293+ .. code-block :: html+django
264294
265295 <input name="category" placeholder="Profession" readonly="readonly" type="text">
266296
@@ -269,24 +299,32 @@ Filter chaining
269299===============
270300
271301The order django-widget-tweaks filters apply may seem counter-intuitive
272- (leftmost filter wins)::
302+ (leftmost filter wins):
303+
304+ .. code-block :: html+django
273305
274306 {{ form.simple|attr:"foo:bar"|attr:"foo:baz" }}
275307
276- returns::
308+ returns:
309+
310+ .. code-block :: html+django
277311
278312 <input foo="bar" type="text" name="simple" id="id_simple" />
279313
280314It is not a bug, it is a feature that enables creating reusable templates
281315with overridable defaults.
282316
283- Reusable field template example::
317+ Reusable field template example:
318+
319+ .. code-block :: html+django
284320
285321 {# inc/field.html #}
286322 {% load widget_tweaks %}
287323 <div>{{ field|attr:"foo:default_foo" }}</div>
288324
289- Example usage::
325+ Example usage:
326+
327+ .. code-block :: html+django
290328
291329 {# my_template.html #}
292330 {% load widget_tweaks %}
0 commit comments