fix: trade_policy 宏使用 with context 修复 500

Jinja imported macros did not receive trade_policy from render context, causing Internal Server Error on all instance pages.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-05 00:36:06 +08:00
parent c0ad50a7b5
commit efe7a57e60
9 changed files with 46 additions and 8 deletions
@@ -34,7 +34,7 @@
</div>
{% include order_rule_tips_tpl %}
<form id="add-order-form" action="/add_order" method="post" class="form-row" data-risk-percent="{{ risk_percent }}">
{% from 'trade_policy_fields.html' import trade_policy_symbol, trade_policy_direction %}
{% from 'trade_policy_fields.html' import trade_policy_symbol, trade_policy_direction with context %}
{{ trade_policy_symbol('symbol', 'order-symbol') }}
{{ trade_policy_direction('direction', 'order-direction') }}
<select id="sltp-mode" name="sltp_mode">
+1 -1
View File
@@ -34,7 +34,7 @@
</div>
<div class="row" style="margin-top:10px">
<label>币种</label>
{% from 'trade_policy_fields.html' import trade_policy_symbol %}
{% from 'trade_policy_fields.html' import trade_policy_symbol with context %}
{{ trade_policy_symbol('symbol', 'symbol-input', default_symbol, placeholder='BTC/USDT') }}
<label>关键位</label>
<select id="key-id">
@@ -142,7 +142,7 @@
{% endif %}
</div>
<form id="key-form" action="/add_key" method="post" class="form-row">
{% from 'trade_policy_fields.html' import trade_policy_symbol, trade_policy_direction %}
{% from 'trade_policy_fields.html' import trade_policy_symbol, trade_policy_direction with context %}
{{ trade_policy_symbol('symbol', 'key-symbol') }}
<select name="type" id="key-type-select" required>
{% if position_sizing_mode != 'full_margin' %}
@@ -24,7 +24,7 @@
{% endfor %}
{% endif %}
<form id="trend-pullback-form" action="{{ url_for('preview_trend_pullback') }}" method="post" class="form-row">
{% from 'trade_policy_fields.html' import trade_policy_symbol, trade_policy_direction %}
{% from 'trade_policy_fields.html' import trade_policy_symbol, trade_policy_direction with context %}
{{ trade_policy_symbol('symbol', 'trend-symbol', placeholder='BTC 或 ETH/USDT') }}
{{ trade_policy_direction('direction', 'trend-direction') }}
<input name="leverage" type="number" min="1" step="1" placeholder="杠杆(必填)" required>
@@ -1,4 +1,7 @@
{# 方向 / 币种:env 账户级限制(三所共用宏) #}
{# 方向 / 币种:env 账户级限制(三所共用宏);调用方须 with context #}
{% if trade_policy is not defined %}
{% set trade_policy = {'symbol_restrict_enabled': false, 'direction_restrict_enabled': false, 'symbol_whitelist': [], 'allows_long': true, 'allows_short': true, 'direction_mode': 'both', 'badge_text': ''} %}
{% endif %}
{% macro trade_policy_symbol(name, id, value='', required=true, placeholder='BTC 或 BTC/USDT') -%}
{% if trade_policy.symbol_restrict_enabled and trade_policy.symbol_whitelist %}
<select name="{{ name }}" id="{{ id }}" {% if required %}required{% endif %} class="trade-policy-symbol-select">