简体   繁体   English

flask和url_for()和werkzeug.routing.BuildError

[英]flask and url_for() and werkzeug.routing.BuildError

This is a pretty simple blueprint/controller: 这是一个非常简单的蓝图/控制器:

maintenance_controller = Blueprint('maintenance', __name__, url_prefix='/maintenance')

@maintenance_controller.route('/csv', methods=['GET','POST'])
def csv():
    return render_template('/maintenance/csv.html')

Then, in csv.html : 然后,在csv.html

<form action="{{ url_for('csv') }}">
...
</form>

However, this yields an exception: 但是,这会产生一个例外:

werkzeug.routing.BuildError
BuildError: ('/csv', {}, None)

What am I missing? 我想念什么?

You'll need to give a blueprint-relative path: 您需要提供一个相对于蓝图的路径:

<form action="{{ url_for('.csv') }}">

provided the template is in the same blueprint. 如果模板在相同的蓝图中。 For templates outside of the blueprint you need to include the blueprint name: 对于蓝图之外的模板,您需要包括蓝图名称:

<form action="{{ url_for('maintenance.csv') }}">

See the Building URLs section of the Blueprints documentation. 请参阅“蓝图”文档的“ 构建URL”部分

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM