0
Hello, I’m starting with Django now and wanted to know how to pass the value of the database to a Djando field using HTML to save the edit.
Na minha View:
@login_required
def editar_aluno(request, id):
aluno = Aluno.objects.get(id=id)
if request.POST:
form = FormAluno(request.POST, instance=aluno)
if form.is_valid():
form.save()
return redirect(lista_aluno)
else:
form = FormAluno(instance=aluno)
return render(request, 'editar_aluno.html', locals())
<form role="form" class="form-horizontal" method="post" action="#" enctype="multipart/form-data">
{% csrf_token %}
<div class="form-group">
<label class="col-md-2 control-label">Nome</label>
<div class="col-md-10">
<input type="text" required placeholder="Nome" id="nome" class="form-control" name="nome" style="width:60%">
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">Pai*</label>
<div class="col-md-10">
<input type="text" placeholder="Pai" id="pai" class="form-control" name="pai" style="width:60%">
</div>
</div>