djangosnippets.org: Latest snippets tagged with 'attr'http://djangosnippets.org/tags/attr/2008-04-28T07:46:29.615608-05:00Template Filter attr
2008-04-28T07:46:29.615608-05:00marinhohttp://djangosnippets.org/snippets/729/<p>You can add this code to a file named "field_attrs.py" in a templatetags folder inside an application.</p>
<p>To use it, remember to load the file with the following template tag:</p>
<pre><code>{% load field_attrs %}
</code></pre>
<p>And for each field you want to change the widget's attr:</p>
<pre><code>{{ form.phone|attr:"style=width:143px;background-color:yellow"|attr:"size=30" }}
</code></pre>
Freely redistributableimproved getattr template filter
2007-09-11T03:37:39.558072-05:00luckystarrhttp://djangosnippets.org/snippets/411/<p>I tried to use <a href="http://www.djangosnippets.org/users/joshua/">Joshua's</a> nice and very useful <a href="http://www.djangosnippets.org/snippets/38/">getattr template filter (#38)</a>, but ran into a few problems.</p>
<p>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 …</p>
Freely redistributable