aboutsummaryrefslogtreecommitdiffstats
path: root/docs/api-guide/viewsets.md
diff options
context:
space:
mode:
authorPhilip Douglas2013-09-10 13:09:25 +0100
committerPhilip Douglas2013-09-10 13:09:25 +0100
commit39e13a0d1341c0a0e694acb1522a99470c4037be (patch)
tree27b498f3cbf81faa1ff587d0730e07706c7551a8 /docs/api-guide/viewsets.md
parentef7ce344865938bea285a408a7cc415a7b90a83c (diff)
parentf5c34926d6a4b4b29fb083d25b99b10d7431eee4 (diff)
downloaddjango-rest-framework-39e13a0d1341c0a0e694acb1522a99470c4037be.tar.bz2
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'docs/api-guide/viewsets.md')
-rw-r--r--docs/api-guide/viewsets.md13
1 files changed, 13 insertions, 0 deletions
diff --git a/docs/api-guide/viewsets.md b/docs/api-guide/viewsets.md
index 0c68afb0..2e65b7a4 100644
--- a/docs/api-guide/viewsets.md
+++ b/docs/api-guide/viewsets.md
@@ -19,6 +19,12 @@ Typically, rather than explicitly registering the views in a viewset in the urlc
Let's define a simple viewset that can be used to list or retrieve all the users in the system.
+ from django.contrib.auth.models import User
+ from django.shortcuts import get_object_or_404
+ from myapps.serializers import UserSerializer
+ from rest_framework import viewsets
+ from rest_framewor.responses import Response
+
class UserViewSet(viewsets.ViewSet):
"""
A simple ViewSet that for listing or retrieving users.
@@ -41,6 +47,9 @@ If we need to, we can bind this viewset into two separate views, like so:
Typically we wouldn't do this, but would instead register the viewset with a router, and allow the urlconf to be automatically generated.
+ from myapp.views import UserViewSet
+ from rest_framework.routers import DefaultRouter
+
router = DefaultRouter()
router.register(r'users', UserViewSet)
urlpatterns = router.urls
@@ -133,6 +142,10 @@ The `@action` decorator will route `POST` requests by default, but may also acce
@action(methods=['POST', 'DELETE'])
def unset_password(self, request, pk=None):
...
+
+The two new actions will then be available at the urls `^users/{pk}/set_password/$` and `^users/{pk}/unset_password/$`
+
+
---
# API Reference