Django doesn't raise form error on client side if form isn't valid

So I have the following model and modelform which are handled by a view. Now if a user enters a number > 99.99 on the number input the form validation fails due to the specified parameters of field monthly_amount which is fine. However, there is no error displayed on the frontend.

class Benefit(models.Model):
    company = models.ForeignKey('company.Company', on_delete=models.CASCADE)
    monthly_amount = models.DecimalField(max_digits=4, decimal_places=2, blank=True, null=True)
    ...

    def __str__(self):
        return f'ompany {self.company.name}'
class BenefitForm(ModelForm):
    class Meta:
        model = Benefit
        exclude = ('company', )
    ...

    monthly_amount = forms.DecimalField(label='Monthly $ equivalent', widget=forms.NumberInput(attrs={'class': benefit_tailwind_class}))

And this is y view handling the form

def render_dashboard_benefits(request):
    # Get a qs of available Benefits the company of the authenticated user offers
    current_user = request.user
    qs_benefits = Benefit.objects.filter(company__userprofile=current_user).order_by('-created_at')

    ctx = {
        'page': 'Benefits',
        'qs_benefits': qs_benefits,
    }

    # Create a blank form instance on GET requests and add it to the context
    if request.method == 'GET':
        form = BenefitForm()
        ctx['form'] = form
    else:
        # Create clean form
        form = BenefitForm()
        ctx['form'] = form

        # Create new Benefit instance on POST request
        new_benefit = BenefitForm(request.POST)

        if new_benefit.is_valid():

            # If the instance is valid create it but dont save it yet
            new_benefit_instance = new_benefit.save(commit=False)

            # Get the related company instance and assign it to the model instance
            new_benefit_instance.company = current_user.company

            # Finally save the instance
            new_benefit_instance.save()

            return render(request, 'dashboard/dashboard_benefits.html', ctx)
        else:
            # Return failed form instance to display error
            print(new_benefit.errors)
            ctx['form'] = new_benefit
            return render(request, 'dashboard/dashboard_benefits.html', ctx)

    return render(request, 'dashboard/dashboard_benefits.html', ctx)
# template

..
{{ form.non_field_errors }}
..

When i print the failed form instsance's errors I get

<ul class="errorlist"><li>monthly_amount<ul class="errorlist"><li>Ensure that there are no more than 2 digits before the decimal point.</li></ul></li></ul>

But how to show this to the user?

Back to Top