0

我在使用flaskand方面还很陌生flask-RESTPlus。我有以下内容,但不清楚如何确定获取请求中使用了哪个路径?

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 a block address')
    def get(self, address):
        # How do I know what get path was called?
        pass
4

2 回答 2

1

url_for通过大量的挖掘,我在烧瓶导入中发现了这一点。

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

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

所以这行得通,我得到了想要的结果。

于 2018-04-29T12:53:05.503 回答
1

更好的解决方案是使用请求上下文。要获取完整路径,您可以执行以下操作:

from flask import request

def get(self, address):
    # How do I know what get path was called?
    print(request.full_path)
于 2018-06-07T16:37:36.967 回答