python
runtime_error
ai_generated
true
运行时错误:未找到应用程序。要么您不在 Starlette 应用程序中运行,要么未设置 'app' 变量。
RuntimeError: No application found. Either you are not running inside a Starlette application or you have not set the 'app' variable.
ID: python/starlette-runtime-error-no-application
80%修复率
82%置信度
0证据数
2024-11-18首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
试图在 Starlette 应用上下文之外使用 request 或 response 对象。
English
试图在 Starlette 应用上下文之外使用 request 或 response 对象。
解决方案
-
100% 成功率
from starlette.requests import Request @app.route('/') async def index(request: Request): return JSONResponse({'message': 'Hello'})
无效尝试
常见但无效的做法:
-
95% 失败
request 对象依赖于请求上下文,无法在全局创建
-
80% 失败
没有正确初始化上下文,仍然会报错