Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define URL root with flask

I have multiple routes which have the same URL root. Example:

  • abc/def/upload
  • abc/def/list
  • abc/def/page/{page_id}

Can I define abc/def to be URL root. (Something similar to what can be done in Java using Spring or Apache CXF)

Thanks

like image 569
Harshdeep Avatar asked Sep 09 '26 05:09

Harshdeep


1 Answers

In flask-restful it is possible to prefix all your routes on api initialization:

>>> app = Flask(__name__)
>>> api = restful.Api(app, prefix='/abc/def')

You can then wire your resources ignoring any prefixes:

>>> api.add_resource(MyResource, '/upload')
>>> ...
like image 91
el.atomo Avatar answered Sep 11 '26 19:09

el.atomo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!