Login

Template Filter attr

Author:
marinho
Posted:
April 28, 2008
Language:
Python
Version:
.96
Tags:
field attr filter template newforms form forms
Score:
5 (after 5 ratings)

You can add this code to a file named "field_attrs.py" in a templatetags folder inside an application.

To use it, remember to load the file with the following template tag:

{% load field_attrs %}

And for each field you want to change the widget's attr:

{{ form.phone|attr:"style=width:143px;background-color:yellow"|attr:"size=30" }}
1
2
3
4
5
6
7
8
9
from django import template

register = template.Library()

@register.filter_function
def attr(obj, arg1):
    att, value = arg1.split("=")
    obj.field.widget.attrs[att] = value
    return obj

More like this

  1. Custom CSS class in Form with template tag filter by kegan 5 years, 11 months ago
  2. Advanced Search in django admin by visik7 4 years, 4 months ago
  3. Honeypot Field by SmileyChris 8 years, 2 months ago
  4. Form row filter by kylefox 7 years, 3 months ago
  5. order_by template filter by marinho 7 years ago

Comments

Please login first before commenting.