E
E
Egegey2020-07-25 16:00:04
Django
Egegey, 2020-07-25 16:00:04

Django. How to set custom error text for a form field?

class Url(models.Model):
    full = models.URLField(max_length=300, verbose_name='Полный URL',
                           error_messages={'invalid': 'Введите корректный адрес'},
                           validators=[validators.URLValidator(message='Введите корректный адрес', 
                                                                                    code='invalid')])


In this model, I cannot specify the correct error text if I specify an invalid URL.
The standard message is constantly displayed.
In the full field , I specified the error_messages and validators parameters in different ways, with and without them - the error is the same.
In the form itself, I do not set any checks, I just display the form and that's it.

5f1c2c3b1fc5c618098382.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question