0

I am fairly new at working with flask and flask-RESTPlus. I have the following and it is not clear how can I determine which path was used in the get request?

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
Frank C.
  • 7,758
  • 4
  • 35
  • 45

2 Answers2

1

Through lot's of digging I found that url_for in flask import.

Still feels a bit wonky but I can create a fully qualified link with:

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

So this works and I get the desired results.

Frank C.
  • 7,758
  • 4
  • 35
  • 45
1

A better solution would be to use the request context. To get the full path, you can do:

from flask import request

def get(self, address):
    # How do I know what get path was called?
    print(request.full_path)
dmulter
  • 2,608
  • 3
  • 15
  • 24