如何使用flask.url_for()与安稳的瓶颈? [英] How do I use flask.url_for() with flask-restful?
本文介绍了如何使用flask.url_for()与安稳的瓶颈?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
api = Api(app,decorators = [csrf_protect.exempt])
api.add_resource(FTRecordsAPI,
'/api/v1.0/ftrecords/<string:ios_sync_timestamp>',
endpoint =api.ftrecord)
$我想重定向到端点 api.ftrecord
。
但是现在我试图做到这一点:
base_url = flask。 url_for('api.ftrecord')
我得到一个异常。
建立
文件/Users/hooman/workspace/F11A/src/lib/werkzeug/routing.py,第1620行,增加BuildError ('api.ftrecord',{},None)
我错过了什么?
解决方案
您需要为 ios_sync_timestamp
部分网址:
flask.url_for('api.ftrecord',ios_sync_timestamp ='some value')
或者您可以使用 Api.url_for()
,它需要一个资源:
api.url_for(FTRecordsAPI,ios_sync_timestamp ='some value')
I have setup Flask restful like this:
api = Api(app, decorators=[csrf_protect.exempt])
api.add_resource(FTRecordsAPI,
'/api/v1.0/ftrecords/<string:ios_sync_timestamp>',
endpoint="api.ftrecord")
I would like to redirect internally to the endpoint api.ftrecord
.
But the moment I try to do this:
base_url = flask.url_for('api.ftrecord')
I get an exception.
File "/Users/hooman/workspace/F11A/src/lib/werkzeug/routing.py", line 1620, in build
raise BuildError(endpoint, values, method)
BuildError: ('api.ftrecord', {}, None)
What am I missing please?
解决方案
You'll need to specify a value for the ios_sync_timestamp
part of your URL:
flask.url_for('api.ftrecord', ios_sync_timestamp='some value')
or you could use Api.url_for()
, which takes a resource:
api.url_for(FTRecordsAPI, ios_sync_timestamp='some value')
这篇关于如何使用flask.url_for()与安稳的瓶颈?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文