Last active
August 29, 2015 14:02
-
-
Save eliasson/ce120a9c9fa4f679575b to your computer and use it in GitHub Desktop.
Add CSS class for form widget in Django Templates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import template | |
register = template.Library() | |
@register.filter(name='addcss') | |
def addcss(field, css): | |
""" | |
Adds the given class to the class attribute of the given field. | |
E.g. adds the class 'bar' to the foo widget: | |
{{ form.foo|addcss:"bar" }} | |
""" | |
return field.as_widget(attrs={"class": css}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment