css - django form to apply for designed html elements -


i hve html file:

<form method='post'>     {% csrf_token %}     <input name='foo'/>     <button type="submit">submit</button>  </form> 

now, imagine form has css atributes behind, want form configure inputs. example. field required, min length 10 chars, etc etc.

how approach django forms?

is like:

from django import forms  class inputform(forms.form):     input_line = forms.charfield(max_length=20, min_length=10, name='foo') 

how apply vies.py , how errors out html?

would appreciate reply.

you can try this.

class inputform(forms.form):     input_line = forms.charfield(max_length=30, widget=forms.textinput(attrs={'class' : 'input-field form-control'}))        def clean(self, *args, **kwargs):         cleaned_data = super(inputform, self).clean()         my_input = self.cleaned_data.get("input_line")         if not my_input:             raise forms.validationerror('this field required')         if len(my_input) < 10:             raise forms.validationerror('the min length 10 character')         return cleaned_data 

the clean() method used validating input form.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -