Flask异常" View函数映射正在覆盖现有的端点函数"

时间:2015-06-03 21:48:14

标签: python flask

我跟随这本名为:" Flask web development"。

当我创建他创建的登录系统时,我可以在注册我所做的蓝图时发现异常。

日志:

    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():

希望你能帮忙

1 个答案:

答案 0 :(得分:3)

您有2个名为'/ login'的端点。改变他们的一个名字。此外,这些功能也不能具有相同的名称。