python
runtime_error
ai_generated
true
Werkzeug 路由错误:无法为端点 'external' 构建 URL,包含值 ['scheme', 'host']。你是想用 'index' 吗?
werkzeug.routing.BuildError: Could not build url for endpoint 'external' with values ['scheme', 'host']. Did you mean 'index' instead?
ID: python/flask-url-for-external-scheme
80%修复率
84%置信度
0证据数
2024-09-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
尝试使用 url_for 引用不存在的端点,或提供了路由中未定义的额外参数。
English
Attempting to use url_for with an endpoint that doesn't exist or with extra parameters not defined in the route.
解决方案
-
100% 成功率
Define the route correctly: @app.route('/external') def external(): return 'ok', then use url_for('external') -
80% 成功率
If external URL needed, use url_for('index', _external=True) if index exists
无效尝试
常见但无效的做法:
-
90% 失败
The endpoint still doesn't exist; _external only affects the URL scheme.
-
80% 失败
These are not valid parameters for route building unless defined in the route.