Javascript 烧瓶法不允许500

Javascript 烧瓶法不允许500,javascript,jquery,python,ajax,flask,Javascript,Jquery,Python,Ajax,Flask,我正在制作登录表单,收到以下消息: Method Not Allowed The method is not allowed for the requested URL. 读取a表明flask处理程序的URI应该与表单的action属性中指定的URI相同。我试图使用jquery中的ajax API将表单字段作为json对象的一部分提交: form.html <form id="signin_form_id" onsubmit="sign_in()" method="post">

我正在制作登录表单,收到以下消息:

Method Not Allowed

The method is not allowed for the requested URL.
读取a表明flask处理程序的URI应该与表单的action属性中指定的URI相同。我试图使用jquery中的ajax API将表单字段作为json对象的一部分提交:

form.html

<form id="signin_form_id" onsubmit="sign_in()" method="post">
        <label>Email: </label><input id="email0" type="email" name="l_email" required>
        <br>
        <label>Password: </label><input id="password0" type="password" name="l_password" required>
        <br><br>
        <input type="submit" value="Submit">
</form>
<!-- Body of the index page -->
<body>

    <div class id="main"></div>

    <script>
        <!-- Display index page if session token not set -->
        {% if page_body %}
        if (localStorage.getItem("token") === null) {
            document.getElementById("main").innerHTML = {{ page_body|safe }}
        }
        {% endif %}
    </script>

  </body>
处理请求的服务器端代码为:

serverside.py

@app.errorhandler(400)
def page_not_found(e):
    # This page is returned if the request does not contain a json object
    page_body = 'document.getElementById(\"welcomeview\").innerHTML;'
    return render_template('client.html', page_body=page_body)

@app.route('/sign_in', methods=['POST'])
def sign_in_helper():
    json_obj, code = decorator(sign_in, request, check_token=False)
    # Check if the credentials are valid
    if code == 401:
        # Invalid login
        page_body = 'document.getElementById(\"welcomeview\").innerHTML; alert(\"Invalid credentials!\")'
        return render_template('client.html', page_body=page_body)
    else:
        # Return the token, the operation completion flag and the response code
        return json_obj, code

def sign_in(email, password):
    data = query_db('SELECT * FROM Users WHERE email = ?', [email], one=True)

    if data and check_password_hash(data["password"], password):
        token = token_creator()
        insert_db('UPDATE Users SET token = ? WHERE email = ?', [token, email])
        return jsonify(
            successSignIn=True,
            message="Welcome",
            data=json.dumps({'token': token}),
        ), 200
    return jsonify(
        successSignIn=False,
        message="Username or password invalid"), 401

def decorator(func, request, check_token):
    data = request.get_json(force=True)

    try:
        if check_token:
            token = data.get('token', None)
            if token:
                user = query_db('SELECT * FROM Users WHERE token = ?', [token], one=True)
                if user:
                    json_obj, code = func(**data)
                else:
                    json_obj = jsonify(success=False, message='Invalid token')
                    code = 401
            else:
                json_obj = jsonify(success=False, message='Misformatted data.')
                code = 400
        else:
            json_obj, code = func(**data)
    except (KeyError, TypeError, ValueError):
        json_obj = jsonify(success=False, message='Misformatted data.')
        code = 400
    return json_obj, code
如果我在中将表单的action属性设置为/sign\u,则不再发送错误,但是表单数据有两个提交:一个来自表单,另一个来自AJAX调用

为什么jquery调用中没有相应地设置内部html

@app.errorhandler(400)
def page_not_found(e):
    # This page is returned if the request does not contain a json object
    page_body = 'document.getElementById(\"welcomeview\").innerHTML;'
    return render_template('client.html', page_body=page_body)

@app.route('/sign_in', methods=['POST'])
def sign_in_helper():
    json_obj, code = decorator(sign_in, request, check_token=False)
    # Check if the credentials are valid
    if code == 401:
        # Invalid login
        page_body = 'document.getElementById(\"welcomeview\").innerHTML; alert(\"Invalid credentials!\")'
        return render_template('client.html', page_body=page_body)
    else:
        # Return the token, the operation completion flag and the response code
        return json_obj, code

def sign_in(email, password):
    data = query_db('SELECT * FROM Users WHERE email = ?', [email], one=True)

    if data and check_password_hash(data["password"], password):
        token = token_creator()
        insert_db('UPDATE Users SET token = ? WHERE email = ?', [token, email])
        return jsonify(
            successSignIn=True,
            message="Welcome",
            data=json.dumps({'token': token}),
        ), 200
    return jsonify(
        successSignIn=False,
        message="Username or password invalid"), 401

def decorator(func, request, check_token):
    data = request.get_json(force=True)

    try:
        if check_token:
            token = data.get('token', None)
            if token:
                user = query_db('SELECT * FROM Users WHERE token = ?', [token], one=True)
                if user:
                    json_obj, code = func(**data)
                else:
                    json_obj = jsonify(success=False, message='Invalid token')
                    code = 401
            else:
                json_obj = jsonify(success=False, message='Misformatted data.')
                code = 400
        else:
            json_obj, code = func(**data)
    except (KeyError, TypeError, ValueError):
        json_obj = jsonify(success=False, message='Misformatted data.')
        code = 400
    return json_obj, code