在这段代码中,我试图在烧瓶中提取表单数据,但它返回的是非类型而不是字符串。我也在形式中包含了name属性,但它仍然给出了form类型。实际上,我希望访问表单数据,以便在csv或txt文件中打印。也请帮忙。
<!doctype html>
<html lan="en" dir="ltr">
<head>
<meta charset="UTF-8">
<title>Details</title>
<link rel="stylesheet" href="styles.css">
<meta name="viewport" content="width=device-width" ,initial-scale=1>
</head>
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@200&display=swap');
*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
body{
display: flex;
height: 100vh;
justify-content: center;
align-items: center;
background: linear-gradient(135deg,#71b7e6,#9b59b6);
}
.container{
max-width: 700px;
width: 100%;
background: #fff;
padding: 25px 30px;
border-radius: 20px;
}
.container .title{
font-size: 25px;
font-weight: 500;
position: relative;
}
.container .title::before{
content: "";
position: absolute;
left: 0;
bottom: 0;
height: 3px;
width: 50px;
background: linear-gradient(135deg,#71b7e6,#9b59b6);
}
.container form .user-detail{
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
form .user-detail .input-box{
margin: 1px 0 5px 0;
width: cal(100% /2-20px);
}
.user-detail .input-box .details{
font-weight: 500;
margin-bottom: 5px;
}
.user-detail .input-box input{
height: 45px;
width: 100%;
outline: none;
border-radius: 5px;
border: 1px solid #ccc;
padding-left: 15px;
font-size: 16px;
border-bottom-width: 2px ;
transition: all 0.3s ease;
}
.user-detail .input-box input:focus,
.user-detail .input-box input:valid{
border-color:#9b59b6;
}
form .gender-details{
font-size: 20px;
font-weight: 500;
}
form .gender-details .gender-title{
font-size: 15px;
font-weight: 500;
}
form .gender-details .category{
display: flex;
width: 80%;
justify-content: space-between;
margin: 14px 0;
}
.gender-details .category label{
display: flex;
align-items: center;
}
.gender-details .category .dot{
height: 18px;
width: 18px;
background: #d9d9d9;
border-radius: 50%;
margin-right: 10px;
border: 2px solid transparent;
}
#dot-1:checked ~ .category .one,
#dot-2:checked ~ .category .two,
#dot-3:checked ~ .category .three{
border-color: #d9d9d9;
background: #9b59b6;
}
form input[type="radio"]{
display: none;
}
form .button{
height: 45px;
margin: 45px 0;
}
form .button input{
height: 100%;
width: 100%;
outline: none;
color: #fff;
font-size: large;
font-weight:1000;
border-radius: 20px;
background: linear-gradient(135deg,#9b59b6,#71b7e6);
}
form .button input:hover{
background: linear-gradient(-135deg,#9b59b6,#71b7e6);
}
</style>
<body>
<div class="container">
<div class="title">Personal Details</div>
<br>
<form action ="form_2">
<div class="user-detail">
<div class="input-box">
<span class="details">Full Name</span>
<input type="text" name="full_name" class="form-control" placeholder="Enter your Name">
</div>
<br>
<div class="input-box">
<span class="details">Username</span>
<input name="username" placeholder="Enter your Username">
</div>
<br>
<div class="input-box">
<span class="details">Contact </span>
<input name="contact" placeholder="Enter your contact number">
</div>
<br>
<div class="input-box">
<span class="details">Address</span>
<input name="address" placeholder="Enter your Address">
</div>
<br>
</div>
<div class="gender-details">
<input type="radio" name="Gender" id="dot-1">
<input type="radio" name="Gender" id="dot-2">
<input type="radio" name="Gender" id="dot-3">
<span class="gender-title">Gender</span>
<div class="category">
<label for="dot-1">
<span class="dot one"></span>
<span class="gender">Male</span>
</label>
<label for="dot-2">
<span class="dot two"></span>
<span class="gender">Female</span>
</label>
<label for="dot-3">
<span class="dot three"></span>
<span class="gender">Prefer not to Say</span>
</label>
</div>
</div>
<div class="button">
<input type="submit" value="Register">
</div>
</form>
</div>
</body>
</html>烧瓶
from flask import Flask, render_template,request
app = Flask(__name__)
@app.route('/')
def cover():
return render_template('cover.html')
# return "Hello World"
@app.route('/signup/form_2',methods=['GET','POST','DELETE'])
def phpu():
name=request.form.get("full_name")
username=request.form.get("username")
contact=request.form.get("contact")
address=request.form.get("address")
print(type(name))
render_template('form_2.html',title=title,name=name,username=username,contact=contact,address=address)
if __name__ == "__main__":
app.run(debug=True, port=8000)请帮我,这件事一直没有退货。谢谢你!!
发布于 2021-07-01 11:52:45
表单操作是不正确的。它必须如下:
<form action ="signup/form_2">如果更新不起作用,为POST方法添加一个If语句,如下所示:
@app.route('/signup/form_2',methods=['GET','POST','DELETE'])
def phpu():
if request.method=='POST':
name=request.form.get("full_name")
...etchttps://stackoverflow.com/questions/68209058
复制相似问题