python config_error ai_generated true

断言错误:名称 'auth' 未注册为蓝图。您是否忘记注册它?

AssertionError: The name 'auth' is not registered as a blueprint. Did you forget to register it?

ID: python/flask-blueprint-not-registered

其他格式: JSON · Markdown 中文 · English
80%修复率
85%置信度
0证据数
2024-06-01首次发现

版本兼容性

版本状态引入弃用备注
3.x active

根因分析

蓝图必须在 Flask 应用程序中注册后才能使用。

English

A blueprint must be registered with the Flask app before it can be used.

generic

解决方案

  1. 100% 成功率 Register the blueprint with the app
    from myapp.auth import auth_bp
    app.register_blueprint(auth_bp)
  2. 95% 成功率 Check the blueprint name and register correctly
    print(auth_bp.name)  # ensure it's 'auth'
    app.register_blueprint(auth_bp, url_prefix='/auth')

无效尝试

常见但无效的做法:

  1. Importing the blueprint but not calling app.register_blueprint 100% 失败

    Registration is required to add routes.

  2. Registering with wrong name 80% 失败

    The name must match the blueprint's name attribute.