請你幫我製作一個web網頁,用flask框架製作,需要實現如下功能,1、可以錄入數據,界面有確認日期、確認班別、確認綫別、不良機種、不良現象、不良ISN.2、數據保存在本地D盤中3、可以調用數據更具日期、綫別、機種、想象查詢到登記的歷史記錄4、要求界面左邊為菜單爛、菜單欄有一個登記數據和一個查詢數據按鈕、按下后跳轉到相對界面
时间: 2023-08-09 14:04:26 浏览: 31
好的,我可以为您提供一份简单的Flask应用程序,实现您所需的功能。首先,需要安装Flask和pandas库。您可以使用以下命令安装它们:
```
pip install Flask
pip install pandas
```
接下来,您可以使用以下代码创建一个简单的Flask应用程序:
```python
from flask import Flask, render_template, request
import pandas as pd
app = Flask(__name__)
# 主页
@app.route('/')
def home():
return render_template('home.html')
# 登记数据
@app.route('/add_data', methods=['GET', 'POST'])
def add_data():
if request.method == 'POST':
date = request.form['date']
shift = request.form['shift']
line = request.form['line']
model = request.form['model']
issue = request.form['issue']
isn = request.form['isn']
# 保存数据到本地
data = {'Date': [date], 'Shift': [shift], 'Line': [line], 'Model': [model], 'Issue': [issue], 'ISN': [isn]}
df = pd.DataFrame(data)
df.to_csv('D:/data.csv', mode='a', index=False, header=not bool(open('D:/data.csv').read()))
return render_template('success.html')
else:
return render_template('add_data.html')
# 查询数据
@app.route('/query_data', methods=['GET', 'POST'])
def query_data():
if request.method == 'POST':
date = request.form['date']
line = request.form['line']
model = request.form['model']
# 读取本地数据
df = pd.read_csv('D:/data.csv')
# 根据条件查询数据
query_df = df.loc[(df['Date'] == date) & (df['Line'] == line) & (df['Model'] == model)]
return render_template('query_data.html', data=query_df.to_dict('records'))
else:
return render_template('query_data.html', data=[])
if __name__ == '__main__':
app.run(debug=True)
```
这个应用程序有三个URL:
1. 主页:`/`
2. 登记数据:`/add_data`
3. 查询数据:`/query_data`
在`templates`文件夹中,您需要创建以下三个HTML模板:
1. `home.html`:主页
2. `add_data.html`:登记数据
3. `query_data.html`:查询数据
这些模板可以通过以下代码创建:
`home.html`:
```html
<!DOCTYPE html>
<html>
<head>
<title>Home Page</title>
</head>
<body>
<h1>菜单栏</h1>
<ul>
<li><a href="{{ url_for('add_data') }}">登记数据</a></li>
<li><a href="{{ url_for('query_data') }}">查询数据</a></li>
</ul>
</body>
</html>
```
`add_data.html`:
```html
<!DOCTYPE html>
<html>
<head>
<title>登记数据</title>
</head>
<body>
<h1>登记数据</h1>
<form method="post">
<label for="date">确认日期:</label><input type="date" name="date" id="date" required><br>
<label for="shift">确认班别:</label><input type="text" name="shift" id="shift" required><br>
<label for="line">确认线别:</label><input type="text" name="line" id="line" required><br>
<label for="model">不良机种:</label><input type="text" name="model" id="model" required><br>
<label for="issue">不良现象:</label><input type="text" name="issue" id="issue" required><br>
<label for="isn">不良ISN:</label><input type="text" name="isn" id="isn" required><br>
<input type="submit" value="提交">
</form>
</body>
</html>
```
`query_data.html`:
```html
<!DOCTYPE html>
<html>
<head>
<title>查询数据</title>
</head>
<body>
<h1>查询数据</h1>
<form method="post">
<label for="date">确认日期:</label><input type="date" name="date" id="date" required><br>
<label for="line">确认线别:</label><input type="text" name="line" id="line" required><br>
<label for="model">不良机种:</label><input type="text" name="model" id="model" required><br>
<input type="submit" value="查询">
</form>
{% if data %}
<h2>查询结果</h2>
<table border="1">
<thead>
<tr>
<th>确认日期</th>
<th>确认班别</th>
<th>确认线别</th>
<th>不良机种</th>
<th>不良现象</th>
<th>不良ISN</th>
</tr>
</thead>
<tbody>
{% for row in data %}
<tr>
<td>{{ row['Date'] }}</td>
<td>{{ row['Shift'] }}</td>
<td>{{ row['Line'] }}</td>
<td>{{ row['Model'] }}</td>
<td>{{ row['Issue'] }}</td>
<td>{{ row['ISN'] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
</body>
</html>
```
这个应用程序将数据保存在本地CSV文件(`D:/data.csv`)中,并且可以根据日期、线别和机种查询历史记录。您可以根据自己的需求对其进行修改和定制化。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)