I am using Django REST Framework and django-rest-swagger library for building an API endpoints. I would like to group some API urls by custom attribute instead of URL.
我正在使用Django REST Framework和django-rest-swagger库来构建API端点。我想通过自定义属性而不是URL对一些API网址进行分组。
For example I have API endpoints and would like to group them by functions:
例如,我有API端点,并希望按功能对它们进行分组:
# task list management
GET /api/tasks/known - get known tasks list with their parameters
GET /api/tasks - get last tasks list with their statuses
# Tasks by ID management
GET /api/task/12345 - get task result/status
DELETE /api/task/12345 - Revoke task
# Task by name management:
# MyTask123
GET /api/tasks/MyTask123 - get task info (parameters, etc)
POST /api/tasks/MyTask123 - async start new task
# MySuperShinyTask777
GET /api/tasks/MySuperShinyTask777 - get task info (parameters, etc)
POST /api/tasks/MySuperShinyTask777 - async start new task
# scheduled tasks management
GET /api/tasks/scheduled - get list of scheduled tasks
# manage exact scheduled tasks
POST /api/tasks/scheduled/MyTask123 - schedule new task
GET /api/tasks/scheduled/12345 - get scheduled task details
PUT /api/tasks/scheduled/12345 - change scheduled task
DELETE /api/tasks/scheduled/12345 - delete scheduled task
So I would like to show them grouped by roles. Now they grouped all only '/api/' and that's it.
所以我想按角色分组。现在他们只将'/ api /'分组,就是这样。
In urls.py
I include it like this:
在urls.py中,我将它包括在内:
url(r'^api/', include('api.urls'), name='my-api-root'),
How can I do custom grouping for django-rest-swagger?
如何为django-rest-swagger进行自定义分组?
1 个解决方案
#1
0
You can have a urls.py in your tasks app (I assume there is one), and declare them in your /tasks urls.
您可以在任务应用程序中使用urls.py(我假设有一个),并在/ tasks URL中声明它们。
One of this for each of your endpoints
其中一个针对您的每个端点
url(r'^ tasks/(?P<task_id>\w+)$',
YourTaskView,
name='task'),
And this in your api root urls.py
这在你的api根urls.py中
url(r'^api/', include('api.tasks.urls'), name='my-api-root'),
BUT, looks like you could use DRF routers
但是,看起来你可以使用DRF路由器
#1
0
You can have a urls.py in your tasks app (I assume there is one), and declare them in your /tasks urls.
您可以在任务应用程序中使用urls.py(我假设有一个),并在/ tasks URL中声明它们。
One of this for each of your endpoints
其中一个针对您的每个端点
url(r'^ tasks/(?P<task_id>\w+)$',
YourTaskView,
name='task'),
And this in your api root urls.py
这在你的api根urls.py中
url(r'^api/', include('api.tasks.urls'), name='my-api-root'),
BUT, looks like you could use DRF routers
但是,看起来你可以使用DRF路由器