我需要用這個框架製作一個物料出入庫系統,需要可以增減數量,出庫入庫輸入料號可以直接插敘到規格和料號
时间: 2024-04-23 12:24:33 浏览: 11
好的,根据您的需求,我可以给您提供一个简单的 Flask 应用程序示例来实现物料出入库系统的增减数功能,同时允许用户输入料号、规格和数量来进行出入库操作,代码如下:
```python
from flask import Flask, render_template, request
app = Flask(__name__)
# 模拟一个数据仓库,用来存储物料信息和库存数量
data = {'001': {'name': '物料1', 'specs': '规格1', 'quantity': 100},
'002': {'name': '物料2', 'specs': '规格2', 'quantity': 200}}
@app.route('/')
def index():
return render_template('index.html', data=data)
@app.route('/add', methods=['POST'])
def add():
item_code = request.form['item_code']
name = request.form['name']
specs = request.form['specs']
quantity = int(request.form['quantity'])
if item_code in data:
data[item_code]['quantity'] += quantity
else:
data[item_code] = {'name': name, 'specs': specs, 'quantity': quantity}
return render_template('index.html', data=data)
@app.route('/subtract', methods=['POST'])
def subtract():
item_code = request.form['item_code']
quantity = int(request.form['quantity'])
if item_code in data:
data[item_code]['quantity'] -= quantity
return render_template('index.html', data=data)
if __name__ == '__main__':
app.run()
```
上面的代码使用一个字典 `data` 来模拟一个数据仓库,存储物料信息和库存数量。在首页中,我们可以展示所有物料的信息和当前库存数量。当用户提交表单来增加或减少某个物料的数量时,我们会更新 `data` 字典中的相应数量信息,并重新渲染首页模板展示更新后的信息。
在同级目录下创建一个名为 `templates` 的文件夹,并在其中创建一个名为 `index.html` 的文件,其中包含以下内容:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>物料出入库系统</title>
</head>
<body>
<h1>物料出入库系统</h1>
<table>
<thead>
<tr>
<th>料号</th>
<th>名称</th>
<th>规格</th>
<th>库存数量</th>
</tr>
</thead>
<tbody>
{% for item_code, item in data.items() %}
<tr>
<td>{{ item_code }}</td>
<td>{{ item['name'] }}</td>
<td>{{ item['specs'] }}</td>
<td>{{ item['quantity'] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<h2>增加库存</h2>
<form method="post" action="/add">
<label>料号:</label>
<input type="text" name="item_code"><br>
<label>名称:</label>
<input type="text" name="name"><br>
<label>规格:</label>
<input type="text" name="specs"><br>
<label>数量:</label>
<input type="number" name="quantity"><br>
<input type="submit" value="提交">
</form>
<h2>减少库存</h2>
<form method="post" action="/subtract">
<label>料号:</label>
<input type="text" name="item_code"><br>
<label>数量:</label>
<input type="number" name="quantity"><br>
<input type="submit" value="提交">
</form>
</body>
</html>
```
上面的模板中包含两个表单,分别用于增加和减少库存数量。用户需要输入料号、名称、规格和数量等信息来进行出入库操作。提交表单时,会调用相应的 Flask 路由并传递表单数据,通过更新 `data` 字典中的数量信息来实现出入库操作,并重新渲染模板展示更新后的信息。
需要注意的是,上述代码仅提供了一个简单示例,实际应用中可能需要考虑更多因素,例如数据验证、安全性等问题。
相关推荐
![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)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)