如何在flask-RESTPlus中获取资源路径?

时间:2018-04-28 12:25:28

标签: python-3.x flask-restful flask-restplus

我在使用flaskflask-RESTPlus时相当新。我有以下内容,我不知道如何确定get请求中使用了哪条路径?

ns = api.namespace('sample', description='get stuff')

@ns.route(
    '/resource-settings/<string:address>',
    '/unit-settings/<string:address>',
    '/resource-proposals/<string:address>',
    '/unit-proposals/<string:address>')
@ns.param('address', 'The address to decode')
class Decode(Resource):
    @ns.doc(id='Get the decoded result of an block address')
    def get(self, address):
        # How do I know what get path was called?
        pass

2 个答案:

答案 0 :(得分:1)

更好的解决方案是使用request context。要获得完整路径,您可以执行以下操作:


DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

答案 1 :(得分:0)

经过多次挖掘,我发现烧瓶导入url_for

仍然感觉有点不稳定,但我可以创建一个完全合格的链接:

result = api.base_url + url_for('resource-settings', address=id)

这样可行,我得到了理想的结果。