Flask 獲取 Form 表單的數據


創建 templates 文件夾,在該文件夾下創建 register.html 文件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>歡迎注冊用戶</h1>
    <form action="/register" method="post">
        <p><input type="text" name="username" placeholder="用戶名"></p>
        <p><input type="password" name="password" placeholder="密碼"></p>
        <p><input type="password" name="repassword" placeholder="確認密碼"></p>
        <p><input type="submit" value="注冊"></p>
    </form>
</body>
</html>

在 app.py 下添加

@app.route('/register', methods=['GET', 'POST'])
def register():
    if request.method == 'POST':
        print(request.form.get('username'))
        print(request.form.get('password'))
        print(request.form.get('repassword'))

        return '注冊成功'

    return render_template('register.html')




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM