Django - Limit the amount of characters allowed to be typed into a textbox -
Django - Limit the amount of characters allowed to be typed into a textbox -
here models.py:
class blog(models.model): blogpost = models.charfield(max_length=200) and here forms.py:
class blogform(forms.modelform): class meta: model = blog fields = ['bloppost'] widgets = { 'blogpost' : forms.textarea(attrs={'rows':5, 'cols':90}) } currently, user can come in in many characters wants textbox , receive error message after user submits text. want user can type in 200 characters , moment reaches 200 characters, textbox not allow user type in else (even before submits it). how go doing this?
use maxlength attribute on textarea html element.
class blogform(forms.modelform): class meta: model = blog fields = ['blogpost'] widgets = { 'blogpost' : forms.textarea(attrs={ 'rows': '5', 'cols': '90', 'maxlength': '200', }), } django django-models textbox django-forms
Comments
Post a Comment