Flask 自动重定向到 /

Flask Automatically Redirecting To /

我正在尝试将表单数据提交到我编写的处理程序函数,但 Flask 一直自动重定向到“/”,这导致了 400 Bad Request 错误。我里面有

<form action="{{url_for(createacc())}}" method="POST">

createacc 是

@app.route('/createacc', methods=['GET', 'POST'])
def createacc():
    if request.method == 'POST':
        name = request.form.get['nameinput']
        print("This is from the main file")

        username = request.form['usernameinput']
        passwd = request.form['passwdinput']
        email = request.form['emailinput']
        credentialhandler.add_user(name, username, email, passwd)
        return redirect(url_for(login()), code=302)

    return render_template("createacc.html")

感谢您的帮助!

编辑:如果我添加网站 HTML 可能会有所帮助

<div class="row">
        <div class="col-md-1"></div>
        <div class="col-md-6">
            <ul style="padding: 3em;">
                <form action="{{url_for(createacc())}}">
                    <div class="form-group">
                            <label for="nameinput">Name</label>
                            <input type="text" class="form-control" id="nameinput" name="nameinput" placeholder="Enter Name">
                    </div>
                    <div class="form-group">
                            <label for="usernameinput">Username</label>
                            <input type="text" class="form-control" id="usernameinput" name="usernameinput" placeholder="Enter Email">
                    </div>
                    <div class="form-group">
                        <label for="emailinput">Email Address</label>
                        <input type="email" class="form-control" id="emailinput" name="emailinput" aria-describedby="emailHelp" placeholder="Enter Email">
                    </div>
                    <div class="form-group">
                        <label for="passwdinput">Password</label>
                        <input type="password" class="form-control" id="passwdinput" name="passwdinput" placeholder="Enter Password">
                    </div>
                    <button type="submit" class="btn btn-primary">Submit</button>
                </form>
            </ul>
        </div>
        <div class="col-md-5"></div>
    </div>

尝试将此用于 form

<form method="POST" action="{{ url_for('createacc') }}">

return redirect(url_for('login'))

还有

the redirect status code. defaults to 302.