AlexH
AlexH

Reputation: 327

In django 1.1, how do I find a form field's max_length attribute

I have a form that looks like this:

class SampleForm(forms.Form):
    text = forms.CharField(max_length=100)

In my django template, I want to reference the fact that the length is 100.

I tried {{ form.text.max_length }} to no avail.

On a related note, how do I reference this value in python?

Upvotes: 2

Views: 837

Answers (1)

Ben James
Ben James

Reputation: 125167

When you have an instance of a Form you can access the fields (and their attributes) like this:

form.fields['text'].max_length

In Django template syntax, this would be:

{{ form.fields.text.max_length }}

Upvotes: 3

Related Questions