[Answered ]-Django 3: ValidationError is not displayed

0👍

Thank you @Sunderam Dubey for helping. I found the answer to my question. The problem was in the create method, I rewrote it a little differently (code below) and I was able to display the error text:

def create(request):
    form = TrainForm()
    if request.method == "POST":
        form = TrainForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('/')
    return render(request, "main/create.html", {"form": form})

1👍

Try to use the looping syntax of showing errors so instead of only {{field.errors}} use it as following:

{% for error in field.errors %}
  {{ error }}
{% endfor %}

Leave a comment