Answers for "show form.errors django"

0

show form.errors django

{% extends 'app/base.html' %}
{% block content %}
<form method="POST" action="{% url 'app-add' %}">
{% csrf_token %}
    <div class="form-group">
        <label for="exampleInputName">Name</label>
        <input type="text" class="form-control" name="name" aria-describedby="name" placeholder="Name">        
    </div>

    {% if form.errors %}
       {% for field in form %}
           {% for error in field.errors %} 
              <div class="alert alert-danger">
                   <strong>{{ error|escape }}</strong>
              </div>
           {% endfor %}
       {% endfor %}
    {% endif %}
    <button type="submit" class="btn btn-primary">Submit</button>
</form>
{% endblock %}
Posted by: Guest on October-17-2021

Browse Popular Code Answers by Language