修复V1.0模板Jinja2 count过滤器Bug

This commit is contained in:
2026-05-29 14:26:06 +08:00
parent 8618867f92
commit 7a16efde9a
2 changed files with 8 additions and 2 deletions

View File

@@ -11,6 +11,10 @@ from loguru import logger
app = Flask(__name__)
app.config['JSON_AS_ASCII'] = False
@app.template_filter('count_item')
def count_item(lst, item):
return lst.count(item)
generator = PPTGenerator()
@app.route('/')

View File

@@ -44,10 +44,12 @@
</div>
<div class="mt-3 text-xs text-gray-500">
<span class="bg-green-100 text-green-700 px-2 py-1 rounded-full mr-1">
静态: {{ project.slide_mapping.values() | list | count('static') }} 页
{% set static_pages = project.slide_mapping.values() | list %}
静态: {{ static_pages | count_item('static') }} 页
</span>
<span class="bg-orange-100 text-orange-700 px-2 py-1 rounded-full">
动态: {{ project.total_slides - (project.slide_mapping.values() | list | count('static')) }} 页
{% set static_count = static_pages | count_item('static') %}
动态: {{ project.total_slides - static_count }} 页
</span>
</div>
</div>