Reputation: 8745
For the view and endpoint below with multiple parameters, how should url_path
be specified for the action decorator?
urls.py:
router.register('utils', views.TableColumnViewSet, basename='TableColumn')
views.py:
@action(detail=False, url_path=r'???')
def table_meta(self, request, catalog=None, schema=None, table=None)
Upvotes: 0
Views: 1090
Reputation: 8745
It's very difficult to find an example with multiple params. The trick is realizing that each parameter in the query string is a "named backreference". Realizing this, the syntax makes total sense: name each param as a backreference, with parentheses.
url:
http://0.0.0.0:8000/utils/table_meta/my_db/my_schema/my_table/
views.py:
Note the named group syntax: each param is surrounded with parentheses and the ?P<name>
syntax names the group:
@action(detail=False, url_path=r'table_meta/(?P<catalog>[^/.]+)/(?P<schema>[^/.]+)/(?P<table>[^/.]+)')
def table_meta(self, request, catalog=None, schema=None, table=None)
Upvotes: 2