Django - How to add html attributes to forms on templates -


suppose have following template:

<div id="openid_input_area"> {{ form.openid_identifier }}     <input name="bsignin" type="submit" value="{% trans "sign in" %}"> </div> 

how can add css class form.openid_identifier?

as adhering soc principles , expect designers improve templates not want on form model on template itself.

i couldn't find on over docs. there way on template?

i've managed code simple solution problem:

i wrote custom template tag:

from django import template  register = template.library()  def htmlattributes(value, arg):     attrs = value.field.widget.attrs       data = arg.replace(' ', '')         kvs = data.split(',')       string in kvs:         kv = string.split(':')         attrs[kv[0]] = kv[1]      rendered = str(value)      return rendered  register.filter('htmlattributes', htmlattributes) 

and have @ template is:

{{ form.openid_identifier|htmlattributes:"class : something, id: openid_identifier" }} 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -