like title,
what's different about list_route
and detail_route
in django-rest-framework?
if I want to get 1
in url xxx/books/1/
,
how can I write url.py
and views.py
?
相关问题
- Django Attribute error 'datetime.timedelta'
- Uploading multiples image with Django Rest Framewo
- How do I mock a third party library inside a Djang
- Django serializers vs rest_framework serializers
- Django Rest Framework does not show content from S
相关文章
- Serialise choice text for IntegerField with choice
- Django Rest Framework custom response message
- Django REST Framework - OAuth2 Consumer API from e
- Django Rest Framework Without Database
- Django Rest Framework - AssertionError Fix your UR
- Django rest framework nested viewsets and routes
- How can I use pagination_class in django-rest-fram
- How would I override the perform_destroy method in
detail_route, is for an instance. What I mean, method generated with detail route, will be appended after an instance method, i.e. a retrieve. {prefix}/{lookup}/
Check : django drf router doc
If your model is books and 1 is the id:
If xxx is your instance, you should user url_path variable to change default url. Something like this:
Then in the method, you will have num as a parmeter
urls.py, will be generated with default router:
@list_route
and@detail_route
are extra actions that we can add to aViewSet
. Both provide a custom routing facility in view set. Any methods on theViewSet
decorated with@detail_route
or@list_route
will also be routed.list_route
will give all the related records, whereasdetail_route
will provide only a particular record. For example, given a method like this on the UserViewSet class:The following URL pattern would additionally be generated:
For more information on routers you can visit the official Django Rest Rramewrok documentation on routers.
If you want get
xxx/books/1/
then yoururl.py
andviews.py
should look like this.urls.py
:views.py
:**Read this and definitely you will get the difference and how to use it **
The difference between the @list_route and @detail_route is the @detail_route decorator contains pk in its URL pattern and is intended for methods which require a single instance. The @list_route decorator is intended for methods which operate on a list of objects (list of records)
Get reference through enter link description here
**////// In API call or in url call
for create user**### forget password