写一个python的HTML订单管理页面。这个页面有一个表格,表格每列标题依次是项目编号、 任务名、客户联系方式、技术联系方式、预算、单价、订单号、状态、时间1,表格默认显示20行。表格下方有个分页功能,这个功能包括最左边有首页上一页,中间就是阿拉伯数字的页码,页码显示前2个和后2个中间用省略号,页码后面有下一页、末页,最后是一个输入框。分页功能中,点击首页,页码跳到1、点击上一页页码跳到当前页减1,点击下一页码跳到当前页加1,点击末页页码跳到最后页。输入框里输入页码,当前页显示该页码。表格的内容总是显示当前页码的数据,默认显示第一页
时间: 2024-02-13 19:07:43 浏览: 148
好的,这是一个简单的Python Flask实现的HTML订单管理页面,满足您的需求:
```python
from flask import Flask, render_template, request
app = Flask(__name__)
# Mock data
orders = [
{"proj_id": "P001", "task_name": "Task 1", "client_contact": "client1@example.com", "tech_contact": "tech1@example.com", "budget": 1000, "price": 100, "order_no": "O001", "status": "Pending", "time1": "2022-01-01"},
{"proj_id": "P002", "task_name": "Task 2", "client_contact": "client2@example.com", "tech_contact": "tech2@example.com", "budget": 2000, "price": 200, "order_no": "O002", "status": "In Progress", "time1": "2022-01-02"},
{"proj_id": "P003", "task_name": "Task 3", "client_contact": "client3@example.com", "tech_contact": "tech3@example.com", "budget": 3000, "price": 300, "order_no": "O003", "status": "Completed", "time1": "2022-01-03"},
# ...More orders
]
# Constants
ROWS_PER_PAGE = 20
@app.route("/", methods=["GET", "POST"])
def index():
# Get current page number from query string parameter
page = int(request.args.get("page", 1))
# Calculate start and end index of orders for current page
start_idx = (page - 1) * ROWS_PER_PAGE
end_idx = start_idx + ROWS_PER_PAGE
# Get orders for current page
current_orders = orders[start_idx:end_idx]
# Calculate total number of pages
total_pages = (len(orders) - 1) // ROWS_PER_PAGE + 1
# Calculate page numbers to display in pagination
page_numbers = []
for i in range(max(1, page - 2), min(total_pages + 1, page + 3)):
page_numbers.append(i)
# Insert ellipses in page numbers if there are gaps
if page_numbers[1] > 2:
page_numbers.insert(1, "...")
if page_numbers[-2] < total_pages - 1:
page_numbers.insert(-1, "...")
# Render HTML template with data
return render_template(
"index.html",
current_orders=current_orders,
page_numbers=page_numbers,
current_page=page,
total_pages=total_pages,
)
if __name__ == "__main__":
app.run(debug=True)
```
注意,这只是一个简单的示例,没有使用数据库或其他实际数据存储。您需要根据您的实际需求进行更改和扩展。
阅读全文