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="lang-py prettyprint-override">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

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -