首页 > 解决方案 > 如何从html中获取数据并将其作为对象,字典,在python中安全

问题描述

这是我的应用程序中的代码

@app.route('/registration', methods=["POST","GET"])
def createuser():
    if request.method == "POST":
        status =request.form("rstatus")
        firstname = request.form("firstname")
        dob = request.form("dob")
        email = request.form("email")
        number = request.form("number")
        password = request.form("password")
        lastname = request.form("lastname")
        nickname = request.form("nickname")
        if status == "Customer":
            db = shelve.open("customer.db","c")
            db[nickname] =[firstname,dob,email,number,password,lastname]
            return render_template("Customer_Dashboard_Profile.HTML")
        elif status == "Staff":
            db = shelve.open("staff.db","c")
            db[nickname] =[firstname,dob,email,number,password,lastname]
            return render_template("Employee_Dashboard_Profile.HTML")
        else:
            print("ERROR")

这是我的html

<form action="/registration" class="form-signin" method="post">
                        <div class="form-label-group">
                            <select name="rstatus" id="rstatus" class="form-control">
                                <option value="Customer" selected>Customer</option>
                                <option value="Staff">Staff</option>
                            </select>
                        </div>
                        <div class="form-label-group">
                            <input type="text" id="inputfirstname" class="form-control" placeholder="First Name" name="firstname" required>
                            <label for="inputFirstname">First Name</label>
                        </div>
                        <div class="form-label-group">
                            <input type="date" id="inputDOB" class="form-control" placeholder="Date of Birth" name="dob"required>
                            <label for="inputDOB">Date of Birth</label>
                        </div>
                        <div class="form-label-group">
                            <input type="email" id="inputEmail" class="form-control" placeholder="Email address" name="email" required autofocus>
                            <label for="inputEmail">Email address</label>
                        </div>
                        <div class="form-label-group">
                            <input type="number" id="inputphonenumber" class="form-control" placeholder="Phone Number" name="number" required min="80000000" max="99999999">
                            <label for="inputphonenumber">Phone Number</label>
                        </div>
                        <div class="form-label-group">
                            <input type="password" id="inputPassword" class="form-control" placeholder="Password" name="password" required>
                            <label for="inputPassword">Password</label>
                        </div>
                        <div class="form-label-group">
                            <input type="password" id="inputconfirmPassword" class="form-control" placeholder="Confirm Password" name="confirmpassword" required>
                            <label for="inputconfirmPassword">Confirm Password</label>
                        </div>
                        <div class="form-label-group">
                            <input type="text" id="inputlastname" class="form-control" placeholder="Last Name" name="lastname" required>
                            <label for="inputlastname">Last Name</label>
                        </div>
                        <div class="form-label-group">
                            <input type="text" id="inputnickname" class="form-control" placeholder="Nickname" name="nickname" required>
                            <label for="inputnickname">Nickname</label>
                        </div>
                        <button class="btn btn-lg btn-primary btn-block text-uppercase" type="submit">Register</button><br>
                    </form>

当我单击注册时,它会导致错误页面显示“未找到 404”。我觉得这个错误与来自 html 页面的请求或获取状态有关,但我不确定到底是什么问题

标签: pythonhtmlflask

解决方案


推荐阅读