Login

Tag "attr"

Snippet List

Template Filter attr

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" }}

  • template
  • filter
  • newforms
  • forms
  • form
  • field
  • attr
Read More

improved getattr template filter

I tried to use [Joshua's](http://www.djangosnippets.org/users/joshua/) nice and very useful [getattr template filter (#38)](http://www.djangosnippets.org/snippets/38/), but ran into a few problems. I used it on objects outside of my control (admin internals, coughcough) and on some of them the code didn't catch the resulting exceptions. So I improved the error handling a bit. Furthermore, the code now also returns the *value of a callable* instead of the callable *itself* (last 4 lines). Looking at my code though, it can certainly be improved further.

  • template
  • filter
  • get
  • attr
Read More

2 snippets posted so far.