Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何解决属性错误:';非类型';对象没有属性';编码';在Django_Javascript_Python_Django_Ajax_Sha256 - Fatal编程技术网

Javascript 如何解决属性错误:';非类型';对象没有属性';编码';在Django

Javascript 如何解决属性错误:';非类型';对象没有属性';编码';在Django,javascript,python,django,ajax,sha256,Javascript,Python,Django,Ajax,Sha256,我尝试使用JAVASCRIPT对HTML文件中的给定表单进行验证,并使用AJAX检查数据库表中的电子邮件是否可用。还从hashlib导入了sha256。但我遇到了类似这样的错误。我不明白为什么会发生这种错误。有人能为这个问题提出解决方案吗 Internal Server Error: /User/Registration/ Traceback (most recent call last): File "C:\PYTHON\lib\site-packages\django\core

我尝试使用JAVASCRIPT对HTML文件中的给定表单进行验证,并使用AJAX检查数据库表中的电子邮件是否可用。还从hashlib导入了sha256。但我遇到了类似这样的错误。我不明白为什么会发生这种错误。有人能为这个问题提出解决方案吗

Internal Server Error: /User/Registration/
Traceback (most recent call last):
  File "C:\PYTHON\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\PYTHON\lib\site-packages\django\core\handlers\base.py", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "D:\Project\salon\user\views.py", line 214, in userregister
    epassword = sha256(upassword.encode()).hexdigest()
AttributeError: 'NoneType' object has no attribute 'encode'
HTML文件:

<!DOCTYPE html>
<html lang="en">
{% load static %}
<head>
    <meta charset="UTF-8">
    <title>User Registration</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <link href="{% static 'styles/style.css' %}" rel="stylesheet"/>
    <script type="text/javascript" language="javascript">
        function getsid(str)
        {   print(str)
            if(window.XMLHttpRequest)
            {
                xmlhttp= new XMLHttpRequest();
            }
            xmlhttp.onreadystatechange=function()
            {
                 if(xmlhttp.readystate==4 &&  xmlhttp.status==200)
                 {
                    document.getElementById("lemail").innerHTML= xmlhttp.responseText;
                 }
           }
             xmlhttp.open("GET","{% url 'checkemail' %}?id="+str,true);
             xmlhttp.send(null);
        }
    </script>
</head>
<body>
   <section class="sreg" id="sreg">
        <div class="container-fluid">
            <div class="htop">
                <h4>User <span>Register Form</span></h4>
            </div>
            <div class="row">
                <div class="col-12">
                        <form method="POST" name="contact" action="{% url 'userregister' %}">
                             {%csrf_token%}
                            <div class="form-row">
                                <div class="form-group col-md-6">
                                    <label for="fname">First Name</label>
                                    <input type="text" class="form-control" id="fname" name="fname" placeholder="First Name">
                                    <span id="lfname"></span>
                                </div>
                                <div class="form-group col-md-6">
                                    <label for="lname">Last Name</label>
                                    <input type="text" class="form-control" id="lname" name="lname" placeholder="Last Name">
                                    <span id="llname"></span>
                                </div>
                            </div>
                             <div class="form-group">
                                 <label for="email">Email</label>
                                 <input type="email" class="form-control" id="email" name="email" placeholder="Email" onchange="getsid(this.value)">
                                 <span id="lemail"></span>
                             </div>
                            <div class="form-group">
                                <label for="password">Password</label>
                                <input type="password" class="form-control" id="password" name="pass" placeholder="Password">
                                <span id="lpass"></span>
                            </div>
                            <div class="form-group">
                                <label for="cpassword">Confirm Password</label>
                                <input type="password" class="form-control" id="cpassword" name="cpass" placeholder="Confirm Password">
                                <span id="lcpass"></span>
                            </div>
                            <div class="form-group">
                                 <label for="mobile">Mobile</label>
                                 <input type="text" class="form-control" id="mobile" name="mobile" placeholder="Mobile">
                                 <span id="lmob"></span>
                             </div>
                             <div class="form-group">
                                 <label for="address">Address</label>
                                 <textarea class="form-control" id="address" name="address" rows="3" placeholder="Address"></textarea>
                                 <span id="laddress"></span>
                             </div>
                             <center>
                                 <button type="submit" class="btn btn-success" onclick="return userregister()">Submit</button>
                              </center>
                        </form>
                </div>
            </div>
        </div>
    </section>
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script src="{% static 'js/scriptfunction.js' %}"></script>
</body>
</html>
url.py

from django.urls import path,re_path
from . import views

urlpatterns=[
    path('User/Registration/', views.userregister, name="userregister"),
    path('User/Registration/CheckEmail', views.checkemail, name="checkemail"),    
    ]

upassword
的值似乎为无

 upassword = request.POST.get('password')
post数据似乎没有密码。您可以检查该值是否从POST请求传递

处理的方法之一是:

try:
    upassword = request.POST['password']
except KeyError:
    // password value not passed in POST request
    // return HTTPResponse with 400 code

当我运行此代码时,post数据没有密码。如何在post请求中传递密码@navyad当我使用'required'进行验证而不是使用onclick函数时,它可以工作。
try:
    upassword = request.POST['password']
except KeyError:
    // password value not passed in POST request
    // return HTTPResponse with 400 code