变量ocode不会传递给def resetusername。 document.getElementById(“ ocode”)。value从storageName获取值,我通过使用“警报”功能对其进行了验证。 谁能告诉我我在做什么错。谢谢
function mySubmit() {
document.getElementById("ocode").value =
localStorage.getItem("storageName");
alert(document.getElementById("ocode").value);
document.getElementById("myform").action = "/postresetusername/";
}
<form method="post" id="myform" onsubmit="mySubmit()">
{% csrf_token %}
<div class = "login-box">
<h1>Reset Username</h1>
<div class = "textbox" style="float:left">
<input type = "email" placeholder="Previous Email" name = "email" id="email">
</div>
<input type='hidden' id= "ocode" name='id' value="">
def postresetusername(request):
email = request.POST.get('email')
ocode = request.POST.get('ocode')
authe.verify_password_reset_code(ocode, "new_pwd")
return render(request, "signIn2.html", {"messg": "Password reset"})
return render(request, "signIn2.html", {"messg": "Cant reset"})
答案 0 :(得分:1)
表单输入使用名称,而您使用的是ID。
<input type='hidden' id= "ocode" name='id' value="">
^^^^^^^^^
后端正在使用
ocode = request.POST.get('ocode')
^^^^^