Crispy_forms_tags not fill form with instance in my update view

Refresh

April 2019

Views

7 time

1

My problem about Update View On my UpdateView when I use {{form.as_p}} , Its work. But when I use {% load crispy_forms_tags %} Form not fill with instance.

My View.py;

def ayarlar (request):
    userinstance=get_object_or_404(kullaniciBilgileri,id=1)
    form =  KullaniciForm(request.POST or None, instance=userinstance)
    if form.is_valid():
        form.save()
    context={
         'form':form,
    }
    return render(request, 'cek/ayar.html',context)

In my template {{forms.as_p}} is working but I wanna this type:


<form action="" method="post">
{% load crispy_forms_tags %}
    {% csrf_token %}
  <div class="form-row" >


    <div class="form-group col-md-6">
      <label>First Name</label>
      <input type="text" name='{{ form.firstName.name }}' class="form-control"  >
    </div>

    <div class="form-group col-md-6">
      <label>Last Name</label>
      <input type="text" name='{{ form.lastName.name }}' class="form-control"  >
    </div>


  </div>

But this type dont fill with instance.

How can I solve this problem

1 answers

0

{% load crispy_forms_tags %} this should be above form tag.

Template

{% load crispy_forms_tags %}

  <form method="post">
    {% csrf_token %}
    {{ form|crispy }}
    <button type="submit" class="btn btn-primary">Sign in</button>
  </form>