I have created a form in Django which has a charfield with max_length=255 as follows:
task = models.CharField(max_length= 255)
Now I want to let the user know how many characters he has typed if he exceeds the 255 characters limit, so I did the following
if form.is_valid():
#some code
else:
messages.info(request,(form.errors.get("task").as_text()))
now suppose if I type 445 characters in the form field and submit then by default I am getting the following error message:
* Ensure this value has at most 255 characters (it has 445).
but instead, I want to change this message to:
Error: maximum length limit is 255 characters (it has 445).
So I tried the following:
class ListForm(ModelForm):
class Meta:
model = ListModel
fields = ["task", "status"]
error_messages = {
'task': {
'max_length': ("Error: maximum length limit is 255 characters"),
},
}
Now the message has been changed to:
* Error: maximum length limit is 255 characters.
My Problem:
- I don't want the
*
which is being displayed in front of the messages - I was not able to capture the number of characters the user has typed, which was being displayed in the default message i.e.
(it has 445)
What can I do to print
Error: maximum length limit is 255 characters (it has 445).
instead of
* Error: maximum length limit is 255 characters.
?
{{ message }}
{% endfor %}{% endif %}`, so I don't think I am using any- "some_string"
` so the