36 lines
979 B
Python
36 lines
979 B
Python
from flask import Blueprint, render_template, request
|
|
from flask_prompt_master.templates.prompts import TEMPLATE_CATEGORIES
|
|
from flask_prompt_master.models import PromptTemplate
|
|
|
|
bp = Blueprint('prompts', __name__)
|
|
|
|
ITEMS_PER_PAGE = 9 # 每页显示的模板数量
|
|
|
|
@bp.route('/prompts')
|
|
def list():
|
|
page = request.args.get('page', 1, type=int)
|
|
category = request.args.get('category', '全部')
|
|
|
|
# 获取模板数据
|
|
query = PromptTemplate.query
|
|
|
|
if category != '全部':
|
|
query = query.filter_by(category=category)
|
|
|
|
# 分页
|
|
pagination = query.paginate(
|
|
page=page,
|
|
per_page=ITEMS_PER_PAGE,
|
|
error_out=False
|
|
)
|
|
|
|
templates = pagination.items
|
|
|
|
return render_template('prompt_list.html',
|
|
templates=templates,
|
|
categories=TEMPLATE_CATEGORIES,
|
|
current_category=category,
|
|
page=page,
|
|
has_next=pagination.has_next,
|
|
total_pages=pagination.pages
|
|
) |