Answer the question
In order to leave comments, you need to log in
How to output errors to a template in Django?
I'm trying to display errors in the template after validation in Django, but I can't display it.
I do this:
In the view
# Создание пользователя
def admin_users_create(request):
args = {}
args.update(csrf(request))
if request.POST:
newuser_form = CustomUserCreationForm(request.POST)
if newuser_form.is_valid():
newuser_form.save()
return redirect('/admin/users/')
else:
args['errors'] = newuser_form.errors.as_data()
return render_to_response('admin/users_create.html', args)
{% if errors %}
<ol>
{% for error in errors %}
<li><strong>{{ error }}</strong></li>
{% endfor %}
</ol>
{% endif %}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question