我需要从views.py获取返回变量,并在html页面中显示值而不重新加载它。有人可以告诉我如何从python脚本到html页面获取变量(在这种情况下,变量为“ completed”的值)
$(document).ready(function(){
$.ajax({
url: "{% url 'check_recovery_email' %}",
type: "POST",
data: { csrfmiddlewaretoken: '{{ csrf_token }}' ,"recovery":remail.value,"code":rcode.value,"email":email.value},
async: false,
});
});
def check_recovery_email(request):
emailr = request.POST.get('recovery')
code = request.POST.get('code')
email = request.POST.get('email')
usernames = database.child("recovery_email").child("details").get()
for user in usernames.each():
userid = user.key()
dtls = database.child("recovery_email").child(userid).child('email').get().val()
if dtls == email:
return JsonResponse({'completed': "ok"})
return render(request, "create_account.html", {"messg": ""})