django - inlineformset - crispy - 如何显示 non_field_errors

django - inlineformset - crispy - how to display non_field_errors

我有以下CreateView

class CreatePerson(CreateView):
    model=Person
    form_class=PersonForm

    def get_context_data(self, **kwargs):

        context = super(CreatePerson, self).get_context_data(**kwargs)
        if self.request.POST:
            context['address_formset'] = AddressInlineFormSet(self.request.POST)
        else:
            context['address_formset'] = AddressInlineFormSet()
        return context

    def form_valid(self, form):
        context = self.get_context_data()
        formset = context['address_formset']
        if formset.is_valid():
            self.object = form.save()
            formset.instance = self.object
            formset.save()
            return super().form_valid(form)
        else:
            return self.render_to_response(self.get_context_data(form=form))

和下面的形式

{% load static crispy_forms_tags %}
...
    {% csrf_token %}
    {% crispy form %}

    {{ address_formset.management_form }}

    {% for formset in address_formset %}
        {% crispy formset %}
    {% endfor %}
    ...

如何在表单中显示重复键错误(出现在formset模型中)?

这个方法我试过了

form_errors = formset.errors
return self.render_to_response(self.get_context_data(form=form,form_errors=form_errors))

{{ form_errors }}

在表格中显示如下。

[{}, {'__all__': ['Please correct the duplicate values below.']}]

如何以酥脆的方式渲染它?

谢谢

我需要的只是...

{% csrf_token %}

{% crispy form  %}

{% crispy address_formset address_formset.form.helper %}