python - flask 异常 "View function mapping is overwriting an existing endpoint function"

标签 python flask

我正在关注这本书:“Flask web 开发”。

当我创建他创建的登录系统时,我可以在注册我制作的蓝图时异常(exception)。

日志:

    C:\Python27\python.exe "C:/Users/Bo/Google Drev/Privat/HobbyProjekter/Event/manage.py"
Traceback (most recent call last):
  File "C:/Users/Bo/Google Drev/Privat/HobbyProjekter/Event/manage.py", line 7, in <module>
    app = create_app(os.getenv('FLASK_CONFIG') or 'default')
  File "C:\Users\Bo\Google Drev\Privat\HobbyProjekter\Event\app\__init__.py", line 42, in create_app
    app.register_blueprint(auth_blueprint, url_prefix='/auth')
  File "C:\Python27\lib\site-packages\flask\app.py", line 62, in wrapper_func
    return f(self, *args, **kwargs)
  File "C:\Python27\lib\site-packages\flask\app.py", line 889, in register_blueprint
    blueprint.register(self, options, first_registration)
  File "C:\Python27\lib\site-packages\flask\blueprints.py", line 153, in register
    deferred(state)
  File "C:\Python27\lib\site-packages\flask\blueprints.py", line 172, in <lambda>
    s.add_url_rule(rule, endpoint, view_func, **options))
  File "C:\Python27\lib\site-packages\flask\blueprints.py", line 76, in add_url_rule
    view_func, defaults=defaults, **options)
  File "C:\Python27\lib\site-packages\flask\app.py", line 62, in wrapper_func
    return f(self, *args, **kwargs)
  File "C:\Python27\lib\site-packages\flask\app.py", line 984, in add_url_rule
    'existing endpoint function: %s' % endpoint)
AssertionError: View function mapping is overwriting an existing endpoint function: auth.login

我注册蓝图的代码如下所示:

from .auth import auth as auth_blueprint
app.register_blueprint(auth_blueprint, url_prefix='/auth')

并且该代码从我的 auth__init__.py 导入:

from flask import Blueprint

auth = Blueprint('auth', __name__)

from . import views
from flask import render_template
from . import auth

@auth.route('/login')
def login():
    return render_template('auth/login.html')

最后我认为我正在尝试注册(只是一个片段):

@auth.route('/login', methods=['GET', 'POST'])
def login():

希望能帮到你

最佳答案

您有 2 个名为“/login”的端点。更改其中一个名字。此外,函数也不能具有相同的名称。

关于python - flask 异常 "View function mapping is overwriting an existing endpoint function",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30631378/

相关文章:

python - 修改 SqlAlchemy 模型时出现 Unhashable Type 错误

python - 为CNN编写训练模型

python - PyQt4:在 trUtf8 字符串中检测到非 ASCII 字符

python - `return` 或 `del` 的类型是什么?

python - 解析 XML 并写入 CSV 文件

python - 如何将对一个 URL 的请求分派(dispatch)到多个线程?

python - Selenium Python 如何从 <div> 获取文本(html 源)

python - Flask/SQLAlchemy - 如何全局使用 latin-1 而不是 UTF-8?

python - Flask app.before_request 移动到其他模块时不起作用

python - @app 和 Flask 中的 app 的区别