class AccountLogin(View):
template_name = 'account/login.html'
def get(self, request, *args, **kwargs):
return render(request, self.template_name, {'form': LoginForm()})
def authenticate_user(self, form):
username = form.cleaned_data['username']
password = form.cleaned_data['password']
return authenticate(username=username, password=password)
def post(self, request, *args, **kwargs):
form = LoginForm(request.POST)
if form.is_valid():
user = self.authenticate_user(form)
if user is not None:
if user.is_active:
login(request, user)
return redirect(settings.LOGIN_REDIRECT_URL)
else:
error_msg = _("Usuário Inativo. Por favor, entre em contato com um Administrador.")
else:
error_msg = _("Usuário/Senha incorretos. Por favor, tente novamente.")
form.add_error(None, error_msg)
form.add_error(None, 'ERRRR?OR?ORERERE')
return render(request, self.template_name, {'form': form})
{% with form=form %}
{% include "base/_form_error_msgs.html" %}
{% endwith %}
{% if form.errors %}
{% for field in form %}
{% for error in field.errors %}
<div class="alert alert-danger">
<strong>{{ error|escape }}</strong>
</div>
{% endfor %}
{% endfor %}
{{ form.errors }}
{% endif %}
These result came from {{ form.errors }} not for field.errors but I can't show each error separate... on django template I just need to iterate over form.fields and form.non_field_errors
How can I how with that on Jinja2?
Thanks!