0

我有一个内联表单集:

OptionFormset = inlineformset_factory(App, AppOptions, can_delete=True, extra=1,
            fields = ['options', 'conditions'])

提交表单时,我在模板中进行验证:

      {% if formset.errors %}
          <p style="color: red;">
              Please correct the error:
          {{ formset.errors }}
          </p>
      {% endif %}

打印返回:

Please correct the error [{}, {}] 

很明显,form中没有错误,他们的formset.errors中也没有错误,错误大概是在视图中吧?

视图.py:

  def setAppOption(request, app_name):
      app_selected = App.objects.get(app_name=app_name, created_by=request.user)
      formset = OptionsFormSet(instance=fusionTable_selected)
      if request.method == 'POST':
          formset = OptionFormset(request.POST, instance=fusionTable_selected)
            if formset.is_valid():   
              formset.save()

      return render_to_response("ezApp/manage__Options.html", {'formset': formset}, context_instance=RequestContext(request))

模型.py

    class App(models.Model):
        layer_name = models.SlugField(max_length=50)

        def __unicode__(self):
            return self.layer_name

    class AppOptions(models.Model):
        app = models.ForeignKey(EzApp)
        condition = models.CharField('SQL Query Conditions', max_length=100, blank=True)
        option = models.CharField('SQL Query Conditions', max_length=100, blank=True
4

1 回答 1

1

正确显示 formset.errors

{% for dict in formset.errors %}
    {% for error in dict.values %}           
        Please correct the error: {{ error }}
    {% endfor %}
{% endfor %}
于 2013-03-03T02:48:33.333 回答