Routing 模块化应用程序中路由时,Flask url_给出错误

Routing 模块化应用程序中路由时,Flask url_给出错误,routing,flask,jinja2,build-error,url-for,Routing,Flask,Jinja2,Build Error,Url For,我正在Flask中构建一个模块化应用程序,如果我引用当前蓝图中另一个蓝图中的函数,我会不断得到一个构建错误,例如 我有一个文件userProfiles.py @userP.route('/myProfile/', methods=['GET']) def showProfile(): ..... 在另一个文件userAccounts.py中有一个 @userA.route('/login/', methods=['GET', 'POST']) def login(): .

我正在Flask中构建一个模块化应用程序,如果我引用当前蓝图中另一个蓝图中的函数,我会不断得到一个构建错误,例如 我有一个文件userProfiles.py

@userP.route('/myProfile/', methods=['GET']) 
def showProfile():
     .....
在另一个文件userAccounts.py中有一个

@userA.route('/login/', methods=['GET', 'POST'])
def login():
     .....
然后我有一个main.py,它注册所有蓝图并执行app.run()

现在我正试图从showProfile函数中为('userA.login')执行url_,但我一直得到一个-werkzeug.routing.BuildError-。我还没能解决这个问题,没有一个在线解决方案能帮到我

另外,函数的url_在我的模板中也不起作用,出于某种原因,它无法获取函数,我别无选择,只能href指向路径

只需添加多一点信息,我根本没有重复的函数,所有函数及其名称都是唯一的,用于路由的url_在每个蓝图中工作良好

以下是回溯:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1701, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1689, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1687, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1360, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1358, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1344, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/cevdet/PycharmProjects/FlaskProjects/jobperfect/userProfiles.py", line 126, in showProfile
    else: return redirect(url_for('userA.login'))
  File "/usr/local/lib/python2.7/dist-packages/flask/helpers.py", line 361, in url_for
    return appctx.app.handle_url_build_error(error, endpoint, values)
  File "/usr/local/lib/python2.7/dist-packages/flask/helpers.py", line 354, in url_for
    force_external=external)
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/routing.py", line 1607, in build
    raise BuildError(endpoint, values, method)
BuildError: ('userA.login', {}, None)
127.0.0.1 - - [17/Sep/2012 23:55:12] "GET /myP

您如何声明您的蓝图
userA

对蓝图使用
url\u for()
时,端点字符串(作为蓝图标识符)的前缀必须是第一个参数传递的蓝图名称,而不是蓝图分配给的变量名称

subapp = Blueprint('profile', __name__)

@subapp.route('/<username>')
def fetch_profile(username):
    pass

请同时显示两个蓝图在应用程序中注册的代码。
url_for('profile.fetch_profile', username=arg)