生成一个flask网页,内容录入姓名、手机号码、身份证号码
时间: 2023-05-30 21:01:24 浏览: 151
以下是一个简单的 Flask 网页示例,可以录入姓名、手机号码和身份证号码。
```python
from flask import Flask, render_template, request
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/submit', methods=['POST'])
def submit():
name = request.form['name']
phone = request.form['phone']
id_card = request.form['id_card']
# 在这里可以对输入的数据进行处理和验证
return f'姓名:{name},手机号码:{phone},身份证号码:{id_card}'
if __name__ == '__main__':
app.run(debug=True)
```
在根目录下创建一个名为 `templates` 的文件夹,并在其中创建一个名为 `index.html` 的模板文件,内容如下:
```html
<!DOCTYPE html>
<html>
<head>
<title>Flask 网页示例</title>
</head>
<body>
<h1>录入个人信息</h1>
<form method="POST" action="/submit">
<label for="name">姓名:</label>
<input type="text" id="name" name="name" required>
<br>
<label for="phone">手机号码:</label>
<input type="tel" id="phone" name="phone" required>
<br>
<label for="id_card">身份证号码:</label>
<input type="text" id="id_card" name="id_card" required>
<br>
<input type="submit" value="提交">
</form>
</body>
</html>
```
启动应用后,访问 http://localhost:5000 即可看到网页。在表单中输入个人信息,点击提交按钮后,会显示输入的信息。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)