2

I'm trying to set maxlength html attribute in django template but when I try to get the value I specified in my model by using {{field.max_length}} nothing is displayed. I can get any other field value just fine.

Relevant Snippet:

{% for field in form %} {% if "_color" in field.name %} <div class="control-group"> <label class="control-label">{{field.label}}</label> <input type="text" ng-init="{{field.name}}='{{field.value}}'" ng-model="{{field.name}}" ng-change="{{field.name}}_picker={{field.name}}" placeholder="{{field.label}}" maxlength="{{field.max_length}}"> 

1 Answer 1

10

The field you get by iterating trough your form is actually a forms.BoundField, and does not have all the attributes of your Field. You can access the Field instance through the field attribute of your BoundField. So, {{ field.field.max_length }} should work.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.