Значения полей не отображаются после обнаружения ошибки в форме Django

Заполненные в форме значения не отображаются после выдачи ошибки валидации.

{{объект}} Не отображается.

Форма

class EmpresaForm(forms.ModelForm):
    class Meta:
        model = models.Empresa
        fields = [
            "fantasia",
            "razao",
            "cnpj",
            "seguimento"
        ]

View

class EmpresaCreateView(generic.CreateView):
    model = models.Empresa
    form_class = forms.EmpresaForm

Шаблон

<form method="post" enctype="multipart/form-data">
  {% csrf_token %}
  {{form.errors}}
  <div class="form-group row">
  <label class="col-sm-2 col-form-label" for="last_updated">last_updated: </label>
  <input class="form-control col-sm-10" id="last_updated" type="datetime-local" name="last_updated" value="{{ object.last_updated }}" disabled>
  </div>
  <div class="form-group row">
  <label class="col-sm-2 col-form-label" for="created">created: </label>
  <input class="form-control col-sm-10" id="created" type="datetime-local" name="created" value="{{ object.created }}" disabled>
  </div>
  <div class="form-group row">
  <label class="col-sm-2 col-form-label" for="fantasia">fantasia: </label>
  <input class="form-control col-sm-10" id="fantasia" type="text" name="fantasia" value="{{ object.fantasia }}">
  </div>
  <div class="form-group row">
  <label class="col-sm-2 col-form-label" for="razao">razao: </label>
  <input class="form-control col-sm-10" id="razao" type="text" name="razao" value="{{ object.razao }}">
  </div>
  <div class="form-group row">
  <label class="col-sm-2 col-form-label" for="cnpj">cnpj: </label>
  <input class="form-control col-sm-10" id="cnpj" type="text" name="cnpj" value="{{ object.cnpj }}">
  </div>
  <div class="form-group row">
  <label class="col-sm-2 col-form-label" for="seguimento">seguimento: </label>
  <input class="form-control col-sm-10" id="seguimento" type="text" name="seguimento" value="{{ object.seguimento }}">
  </div>
  <input type="submit" value="Save" class="btn btn-primary">
</form>

проверьте правильность написания поля модели может быть орфографическая ошибка

измените этот код :

    <form method="post" enctype="multipart/form-data">
  {% csrf_token %}
  {{form.errors}}
  
  <div class="form-group row">
  <label class="col-sm-2 col-form-label" for="fantasia">fantasia: </label>
  <input class="form-control col-sm-10" id="fantasia" type="text" name="fantasia" value="{{ object.fantasia }}">
  </div>
  <div class="form-group row">
  <label class="col-sm-2 col-form-label" for="razao">razao: </label>
  <input class="form-control col-sm-10" id="razao" type="text" name="razao" value="{{ object.razao }}">
  </div>
  <div class="form-group row">
  <label class="col-sm-2 col-form-label" for="cnpj">cnpj: </label>
  <input class="form-control col-sm-10" id="cnpj" type="text" name="cnpj" value="{{ object.cnpj }}">
  </div>
  <div class="form-group row">
  <label class="col-sm-2 col-form-label" for="seguimento">seguimento: </label>
  <input class="form-control col-sm-10" id="seguimento" type="text" name="seguimento" value="{{ object.seguimento }}">
  </div>
  <input type="submit" value="Save" class="btn btn-primary">
</form>

to:

<form method="post" enctype="multipart/form-data">
  {% csrf_token %}
  {{form.errors}}
  
  <div class="form-group row">
  <label class="col-sm-2 col-form-label" for="fantasia">fantasia: </label>
  <input class="form-control col-sm-10" id="fantasia" type="text" name="fantasia" value="{{ form.fantasia }}">
  </div>
  <div class="form-group row">
  <label class="col-sm-2 col-form-label" for="razao">razao: </label>
  <input class="form-control col-sm-10" id="razao" type="text" name="razao" value="{{ form.razao }}">
  </div>
  <div class="form-group row">
  <label class="col-sm-2 col-form-label" for="cnpj">cnpj: </label>
  <input class="form-control col-sm-10" id="cnpj" type="text" name="cnpj" value="{{ form.cnpj }}">
  </div>
  <div class="form-group row">
  <label class="col-sm-2 col-form-label" for="seguimento">seguimento: </label>
  <input class="form-control col-sm-10" id="seguimento" type="text" name="seguimento" value="{{ form.seguimento }}">
  </div>
  <input type="submit" value="Save" class="btn btn-primary">
</form>
Вернуться на верх