【发布时间】:2020-06-12 19:13:49
【问题描述】:
您好,我的视图集中有一个自定义操作,但除了 detail=True,我不确定如何向路由添加更多参数我想要执行操作以过滤某个类别的医生,网址应该类似于doctor/categories/<int:category_id> 但我在尝试添加参数时找不到页面(404)
@action(detail=False, methods=['get'])
def categories(self, request,*args, **kwargs):
"""
Get a list of doctor profiles from an specific category
"""
data = {
'profile' : 'doctor',
}
return Response(data, status=status.HTTP_200_OK)
编辑--
当尝试这样的事情时
@action(detail=False, methods=['get'], url_path='categories/<int:category_id>')
def categories(self, request,*args, **kwargs):
我仍然收到错误 404,在检查可用路线时我发现了这个
v1/ ^profiles/doctors/categories/<int:category_id>/$ [name='profiles/doctors-categories']
v1/ ^profiles/doctors/categories/<int:category_id>\.(?P<format>[a-z0-9]+)/?$ [name='profiles/doctors-categories']
所以网址在那里......但也许我输入错了?
这是我的网址
http://127.0.0.1:8000/v1/profiles/doctors/categories/1
这是我的 urls.py(简体)
from sanitas.views import doctor_schedule as doctor_schedule_views
router = DefaultRouter()
router.register(r'profiles/doctors', doctor_profiles_views.DoctorProfileViewset, basename='profiles/doctors')
urlpatterns = [
path('', include(router.urls)),
]
希望大家能帮帮我
【问题讨论】:
标签: python django django-rest-framework