Answer the question
In order to leave comments, you need to log in
How to get form.errors error text in view?
Good afternoon.
There was a task to drag an authorization form on each page of the site.
Made through the inclusion tag.
<form method="post" action="{% url 'login' %}">
{% csrf_token %}
<tr>
<td>
<label class="" for="name"></label>
{{ auth_form.username }}
</td>
<td>
<label class="" for="pwd"></label>
{{ auth_form.password }}
<input type="submit" class="header__form_button" value="ОК">
</td>
</tr>
</form>
if request.method == 'POST':
form = AuthUserFormPanel(data=request.POST)
if form.is_valid():
login(request, form.get_user())
return HttpResponseRedirect(request.META.get('HTTP_REFERER'), '/')
messages.add_message(request, messages.ERROR, form.errors)
return HttpResponseRedirect(request.META.get('HTTP_REFERER'), '/')
<ul class="errorlist"><li>__all__<ul class="errorlist nonfield"><li>Пожалуйста, введите правильные имя пользователя и пароль. Оба поля могут быть чувствительны к регистру.</li></ul></li></ul>
Please enter the correct username and password. Both fields can be case sensitive.
Answer the question
In order to leave comments, you need to log in
Of course, you can’t throw the form into any view.you can do this
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question