请我尝试使用此How can I build multiple submit buttons django form?
但它对我不起作用,也是django编程的新手 我的目标是:当用户点击按钮recherche时输入标识符我希望输入标签上的所有信息都是我的代码 views.py:
def modifierEmploye(request):
if request.method=='POST':
emp2=EmployeForm(request.POST)
if emp2.is_valid():
if 'recherche' in request.POST:
return HttpResponse("recherche")
elif 'enregistrer' in request.POST:
return HttpResponse("enregistrer")
else:
emp2=EmployeForm()
return render(request,"GPI/modifierEmploye.html",locals())
HTML:
<form action="" method="POST">
{% csrf_token %}
<p> <input id="id" maxlength="200" name="id" type="text" placeholder="identifiant" /></p><br>
<p> <input id="id_nom" maxlength="200" name="nom" type="text" placeholder="Nom" /></p><br>
<p><input id="id_prenom" maxlength="200" name="prenom" type="text" placeholder="Prenom"/></p><br>
<p> <input id="id_departement" maxlength="200" name="departement" type="text" placeholder="Département" /></p><br>
<p> <input id="id_poste" maxlength="200" name="poste" type="text" placeholder="Poste" /></p><br>
<p> <input id="id_telephone" maxlength="200" name="telephone" type="text" placeholder="Téléphone" /></p><br>
<p><input id="id_email" maxlength="200" name="email" type="email" placeholder="Email" /></p>
<p> <input id="id" maxlength="200" name="id" type="text" placeholder="Nom" /></p><br>
<br>
<input type="submit" value="Rechercher" name="recherche" />
<input type="submit" value="Enregistrer" name="enregistrer" />
</form>
这个程序不起作用,请qomeone帮助我
答案 0 :(得分:0)
使用此更改模板,它将起作用:
<form action="" method="POST">
{% csrf_token %}
{{emp2.as_p}}
<input type="submit" value="Rechercher" name="recherche" />
<input type="submit" value="Enregistrer" name="enregistrer" />
</form>