This commit is contained in:
2026-04-27 02:07:31 +08:00
parent 440416ba0c
commit 4ae6898be0
2 changed files with 16 additions and 5 deletions

View File

@@ -1,3 +1,12 @@
{# app_urlJinja 宏,不依赖 Python 往 context 注入;前缀来自中间件 request.state.web_url_prefixWEB_URL_PREFIX或 ASGI root_path #}
{% macro app_url(path) -%}
{%- set _p = path if path.startswith('/') else '/' ~ path -%}
{%- set pre = (request.state.web_url_prefix | default('', true)) | trim -%}
{%- if not pre -%}
{%- set pre = request.scope.get('root_path', '') | trim -%}
{%- endif -%}
{{- pre ~ _p if pre else _p -}}
{%- endmacro %}
<!DOCTYPE html>
<html lang="zh-CN">
<head>
@@ -1038,7 +1047,7 @@
<script src="https://cdn.jsdelivr.net/npm/echarts@5.5.1/dist/echarts.min.js"></script>
<script>
window.__URL_PREFIX__ = {{ url_prefix|tojson }};
window.__URL_PREFIX__ = {{ (request.state.web_url_prefix | default('', true)) | tojson }};
function appPath(p) {
p = p.startsWith("/") ? p : ("/" + p);
var pre = window.__URL_PREFIX__ || "";