F
F
fsociety02021-02-09 11:52:28
Django
fsociety0, 2021-02-09 11:52:28

How to send message with forms.py?

forms.py

class UserPasswordResetForm(PasswordResetForm):
    def __init__(self, *args, **kwargs):
        super(UserPasswordResetForm, self).__init__(*args, **kwargs)

    email = forms.EmailField(label='', widget=forms.TextInput(
        attrs={'class': 'form-control input_user', 'placeholder': 'Электронная почта'}))

    def clean_email(self):
        email = self.cleaned_data.get('email')
        try:
            User.objects.get(email=email)
        except User.DoesNotExist:
            messages.error(request, 'Пользователя с таким email не существует')


Leaving it like this will result in a TypeError
add_message() argument must be an HttpRequest object, not 'module'.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2021-02-09
@bacon

Well, where did request suddenly come from?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question