From 7a7d582d068c7901b09e372e625194c14fe21ba5 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Tue, 11 Sep 2018 11:03:22 +0000 Subject: [PATCH] Deployed 4e093b0e with MkDocs version: 0.16.3 --- .DS_Store | Bin 10244 -> 0 bytes 404.html | 47 +- api-guide/authentication/index.html | 55 +- api-guide/caching/index.html | 514 ++ api-guide/content-negotiation/index.html | 47 +- api-guide/exceptions/index.html | 51 +- api-guide/fields/index.html | 73 +- api-guide/filtering/index.html | 51 +- api-guide/format-suffixes/index.html | 47 +- api-guide/generic-views/index.html | 47 +- api-guide/metadata/index.html | 47 +- api-guide/pagination/index.html | 49 +- api-guide/parsers/index.html | 47 +- api-guide/permissions/index.html | 49 +- api-guide/relations/index.html | 49 +- api-guide/renderers/index.html | 82 +- api-guide/requests/index.html | 47 +- api-guide/responses/index.html | 47 +- api-guide/reverse/index.html | 47 +- api-guide/routers/index.html | 65 +- api-guide/schemas/index.html | 62 +- api-guide/serializers/index.html | 53 +- api-guide/settings/index.html | 66 +- api-guide/status-codes/index.html | 47 +- api-guide/testing/index.html | 55 +- api-guide/throttling/index.html | 49 +- api-guide/validators/index.html | 47 +- api-guide/versioning/index.html | 47 +- api-guide/views/index.html | 47 +- api-guide/viewsets/index.html | 72 +- .../3.0-announcement/index.html | 99 +- .../3.1-announcement/index.html | 103 +- .../3.2-announcement/index.html | 99 +- .../3.3-announcement/index.html | 107 +- .../3.4-announcement/index.html | 107 +- .../3.5-announcement/index.html | 99 +- .../3.6-announcement/index.html | 93 +- .../3.7-announcement/index.html | 99 +- .../3.8-announcement/index.html | 95 +- {topics => community}/contributing/index.html | 97 +- {topics => community}/funding/index.html | 97 +- {topics => community}/jobs/index.html | 103 +- .../kickstarter-announcement/index.html | 97 +- .../mozilla-grant/index.html | 95 +- .../project-management/index.html | 97 +- .../release-notes/index.html | 127 +- .../third-party-packages/index.html | 102 +- .../tutorials-and-resources/index.html | 105 +- img/books/bda-cover.png | Bin 0 -> 47237 bytes img/books/rad-cover.png | Bin 0 -> 14060 bytes img/premium/load-impact-readme.png | Bin 0 -> 23967 bytes index.html | 152 +- mkdocs/search_index.json | 8221 +++++++++-------- sitemap.xml | 178 +- topics/ajax-csrf-cors/index.html | 47 +- topics/api-clients/index.html | 53 +- topics/browsable-api/index.html | 47 +- topics/browser-enhancements/index.html | 47 +- topics/documenting-your-api/index.html | 49 +- topics/html-and-forms/index.html | 49 +- topics/internationalization/index.html | 47 +- topics/rest-hypermedia-hateoas/index.html | 49 +- tutorial/1-serialization/index.html | 61 +- tutorial/2-requests-and-responses/index.html | 53 +- tutorial/3-class-based-views/index.html | 53 +- .../index.html | 57 +- .../index.html | 63 +- tutorial/6-viewsets-and-routers/index.html | 63 +- .../7-schemas-and-client-libraries/index.html | 49 +- tutorial/quickstart/index.html | 60 +- 70 files changed, 7239 insertions(+), 5986 deletions(-) delete mode 100644 .DS_Store create mode 100644 api-guide/caching/index.html rename {topics => community}/3.0-announcement/index.html (98%) rename {topics => community}/3.1-announcement/index.html (94%) rename {topics => community}/3.2-announcement/index.html (95%) rename {topics => community}/3.3-announcement/index.html (92%) rename {topics => community}/3.4-announcement/index.html (94%) rename {topics => community}/3.5-announcement/index.html (96%) rename {topics => community}/3.6-announcement/index.html (94%) rename {topics => community}/3.7-announcement/index.html (95%) rename {topics => community}/3.8-announcement/index.html (94%) rename {topics => community}/contributing/index.html (96%) rename {topics => community}/funding/index.html (96%) rename {topics => community}/jobs/index.html (93%) rename {topics => community}/kickstarter-announcement/index.html (96%) rename {topics => community}/mozilla-grant/index.html (95%) rename {topics => community}/project-management/index.html (96%) rename {topics => community}/release-notes/index.html (98%) rename {topics => community}/third-party-packages/index.html (96%) rename {topics => community}/tutorials-and-resources/index.html (93%) create mode 100644 img/books/bda-cover.png create mode 100644 img/books/rad-cover.png create mode 100644 img/premium/load-impact-readme.png diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 57f03aac0a8f8e9ff155c36facc9244ccfe2f182..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 10244 zcmeHMX>1i$6h2?s-ecy$6eyIk)Ws5vYftE!oEwrrVEhCIh-_$p+EeeH- zF)oM;8e`lLw?stv!={P;fJ9OFp;Adi^oOGVL=p&#Kh$&Y%%i+6$PXk0<|cE`z4x3m zbMJZIxnJ)s5uvm(RzwseA|F3OYARP<6rmSSr;_20^koV5Ct6L7WKfKB)9z&L4R{go zBH%^9i+~paF9J711emi$@hOh>a%HO{<<`NKJOZ%n$-}a6 zo6iB#C+NzMD_b2YUHP5P=>e`Q+#?1Ych(1mIm?hMTOH}R6C8Jf`(?N%6v(f$Ur?G8 zLXPxmF9Kc!I!8d9-Tf4%20phJTzP(Ps*IRcgfo0+q`@@oWMSb6Wc29St9KutzptVM z`puj*dr)~rou)O~`a<0dCyge(ES%KsI<3FG#%ivJTJg$+-el;_by{XLY(^W|NS|(+ zRmP*bT@$s;#`?IljwUSAth8(+X;|?kwMl(#QrL(WrKxI{+EyYtLps(P{C>x3fcVCO z2H|Wk))O{Mzu&i`fA)w`cidfg&!l_Xw9Ekm2W2VBQX{6vlg0yvo>QB6znHey=V(Ue1Om&1W=2BiI_C39 zhtatKrP}7%Yhl-LOrD}tKV-yXn(e+czd#8rGQ$zw)M9?et*BTD)HFGh*XFu|6S9;* zZPco-=Skb{*yJgJz)JDid0{)bph1uGln#q;PYX>i5O z{tku*56PCGo;+>FWn^@K!XSV#uhw}7w{rp!y9-D+we9%#7EePkFgI2@CiP} zAsof`9Z)+rg;z)7=dMxPRF#OER(v&U1>Sq`4qZ>HBh9vpW!jy>^6|?%v)`vKui+oi zYA&@J<1u?#74O7Vyz526i50S)3@01y(r`j*D#OV&tdZ?%%QCsW+_kO|+hd)Uy>4Ae zabbRN{J8Ng`N4H1C9*xSrN!^_`L!o}S)<2JEw2u*Z`rW1l_$vsspJee{mbvqJPi_Du!Y-qjM}H zGlWt}D6>(Cg_2MfGcv=HP;|u6APFUj7RIL_l*jQbo|A;K6|dt>NhsT~LsH5v#;c%| zgE)dV{L}%dT~UgQ)DAS#o04S7Klh_#-*_@9E-uOsjw`w@WRkX&m>o4EOksk3(i9!m zpW28#=|$i+k3bJ+{Xud6KePM)|KH|O@|N#K;MR@+dX`m{mGT->C%2Bv6?g4Hepc}# zim+>Sq;%m*n22$C9nT$c9WU>ec+9;~lKPNq*Xl^=&VJIJrE{DAzyCAfEP3aDaU0;B N|F7wS`Bpst{|oINKrR3P diff --git a/404.html b/404.html index b5ff70705..3d6640212 100644 --- a/404.html +++ b/404.html @@ -179,6 +179,10 @@ Permissions +
  • + Caching +
  • +
  • Throttling
  • @@ -270,76 +274,83 @@ REST, Hypermedia & HATEOAS + + + + +
  • + Caching +
  • +
  • Throttling
  • @@ -270,76 +274,83 @@ REST, Hypermedia & HATEOAS + + + + -
  • - Django OAuth2 Consumer -
  • -
  • JSON Web Token Authentication
  • @@ -801,14 +808,12 @@ REST_FRAMEWORK = {

    For details on configuration and usage see the Django REST framework OAuth documentation for authentication and permissions.

    Digest Authentication

    HTTP digest authentication is a widely implemented scheme that was intended to replace HTTP basic authentication, and which provides a simple encrypted authentication mechanism. Juan Riaza maintains the djangorestframework-digestauth package which provides HTTP digest authentication support for REST framework.

    -

    Django OAuth2 Consumer

    -

    The Django OAuth2 Consumer library from Rediker Software is another package that provides OAuth 2.0 support for REST framework. The package includes token scoping permissions on tokens, which allows finer-grained access to your API.

    JSON Web Token Authentication

    JSON Web Token is a fairly new standard which can be used for token-based authentication. Unlike the built-in TokenAuthentication scheme, JWT Authentication doesn't need to use a database to validate a token. Blimp maintains the djangorestframework-jwt package which provides a JWT Authentication class as well as a mechanism for clients to obtain a JWT given the username and password. An alternative package for JWT authentication is djangorestframework-simplejwt which provides different features as well as a pluggable token blacklist app.

    Hawk HTTP Authentication

    The HawkREST library builds on the Mohawk library to let you work with Hawk signed requests and responses in your API. Hawk lets two parties securely communicate with each other using messages signed by a shared key. It is based on HTTP MAC access authentication (which was based on parts of OAuth 1.0).

    HTTP Signature Authentication

    -

    HTTP Signature (currently a IETF draft) provides a way to achieve origin authentication and message integrity for HTTP messages. Similar to Amazon's HTTP Signature scheme, used by many of its services, it permits stateless, per-request authentication. Elvio Toccalino maintains the djangorestframework-httpsignature package which provides an easy to use HTTP Signature Authentication mechanism.

    +

    HTTP Signature (currently a IETF draft) provides a way to achieve origin authentication and message integrity for HTTP messages. Similar to Amazon's HTTP Signature scheme, used by many of its services, it permits stateless, per-request authentication. Elvio Toccalino maintains the djangorestframework-httpsignature (outdated) package which provides an easy to use HTTP Signature Authentication mechanism. You can use the updated fork version of djangorestframework-httpsignature, which is drf-httpsig.

    Djoser

    Djoser library provides a set of views to handle basic actions such as registration, login, logout, password reset and account activation. The package works with a custom user model and it uses token based authentication. This is a ready to use REST implementation of Django authentication system.

    django-rest-auth

    diff --git a/api-guide/caching/index.html b/api-guide/caching/index.html new file mode 100644 index 000000000..79120cd94 --- /dev/null +++ b/api-guide/caching/index.html @@ -0,0 +1,514 @@ + + + + + + + Caching - Django REST framework + + + + + + + + + + + + + + + + + + + + + +
    + + +
    +
    + + + +
    +
    +
    + + +
    +
    + +
    + + + +

    Caching

    +
    +

    A certain woman had a very sharp conciousness but almost no +memory ... She remembered enough to work, and she worked hard. +- Lydia Davis

    +
    +

    Caching in REST Framework works well with the cache utilities +provided in Django.

    +
    +

    Using cache with apiview and viewsets

    +

    Django provides a method_decorator to use +decorators with class based views. This can be used with +with other cache decorators such as cache_page and +vary_on_cookie.

    +
    from rest_framework.response import Response
    +from rest_framework.views import APIView
    +from rest_framework import viewsets
    +
    +class UserViewSet(viewsets.Viewset):
    +
    +    # Cache requested url for each user for 2 hours
    +    @method_decorator(cache_page(60*60*2))
    +    @method_decorator(vary_on_cookie)
    +    def list(self, request, format=None):
    +        content = {
    +            'user_feed': request.user.get_user_feed()
    +        }
    +        return Response(content)
    +
    +class PostView(APIView):
    +
    +    # Cache page for the requested url
    +    @method_decorator(cache_page(60*60*2))
    +    def get(self, request, format=None):
    +        content = {
    +            'title': 'Post title',
    +            'body': 'Post content'
    +        }
    +        return Response(content)
    +
    + +

    NOTE: The cache_page decorator only caches the +GET and HEAD responses with status 200.

    + + +
    +
    +
    +
    +
    +
    + +
    +

    Documentation built with MkDocs. +

    +
    + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api-guide/content-negotiation/index.html b/api-guide/content-negotiation/index.html index 9733b3ac5..bc817c591 100644 --- a/api-guide/content-negotiation/index.html +++ b/api-guide/content-negotiation/index.html @@ -179,6 +179,10 @@ Permissions +
  • + Caching +
  • +
  • Throttling
  • @@ -270,76 +274,83 @@ REST, Hypermedia & HATEOAS + + + + +
  • + Caching +
  • +
  • Throttling
  • @@ -270,76 +274,83 @@ REST, Hypermedia & HATEOAS + + + +
  • - rest_framework.exceptions.server_error + rest_framework.exceptions.bad_request
  • @@ -654,7 +665,7 @@ API-only application.)

    Set as handler500:

    handler500 = 'rest_framework.exceptions.server_error'
     
    -

    rest_framework.exceptions.server_error

    +

    rest_framework.exceptions.bad_request

    Returns a response with status code 400 and application/json content type.

    Set as handler400:

    handler400 = 'rest_framework.exceptions.bad_request'
    diff --git a/api-guide/fields/index.html b/api-guide/fields/index.html
    index 282f2c5bd..2e7f2bde2 100644
    --- a/api-guide/fields/index.html
    +++ b/api-guide/fields/index.html
    @@ -179,6 +179,10 @@
                         Permissions
                       
                       
    +                  
  • + Caching +
  • +
  • Throttling
  • @@ -270,76 +274,83 @@ REST, Hypermedia & HATEOAS + + + + +
  • + Caching +
  • +
  • Throttling
  • @@ -270,76 +274,83 @@ REST, Hypermedia & HATEOAS + + + + +
  • + Caching +
  • +
  • Throttling
  • @@ -270,76 +274,83 @@ REST, Hypermedia & HATEOAS + + + + +
  • + Caching +
  • +
  • Throttling
  • @@ -270,76 +274,83 @@ REST, Hypermedia & HATEOAS + + + + +
  • + Caching +
  • +
  • Throttling
  • @@ -270,76 +274,83 @@ REST, Hypermedia & HATEOAS + + + + +
  • + Caching +
  • +
  • Throttling
  • @@ -270,76 +274,83 @@ REST, Hypermedia & HATEOAS + + + +
  • The field should have a database index.
  • Using an ordering field that does not satisfy these constraints will generally still work, but you'll be losing some of the benefits of cursor pagination.

    -

    For more technical details on the implementation we use for cursor pagination, the "Building cursors for the Disqus API" blog post gives a good overview of the basic approach.

    +

    For more technical details on the implementation we use for cursor pagination, the "Building cursors for the Disqus API" blog post gives a good overview of the basic approach.

    Setup

    To enable the CursorPagination style globally, use the following configuration, modifying the PAGE_SIZE as desired:

    REST_FRAMEWORK = {
    diff --git a/api-guide/parsers/index.html b/api-guide/parsers/index.html
    index 639d25997..89a6e2aa5 100644
    --- a/api-guide/parsers/index.html
    +++ b/api-guide/parsers/index.html
    @@ -179,6 +179,10 @@
                         Permissions
                       
                       
    +                  
  • + Caching +
  • +
  • Throttling
  • @@ -270,76 +274,83 @@ REST, Hypermedia & HATEOAS + + + + +
  • + Caching +
  • +
  • Throttling
  • @@ -270,76 +274,83 @@ REST, Hypermedia & HATEOAS + + + + +
  • + Caching +
  • +
  • Throttling
  • @@ -270,76 +274,83 @@ REST, Hypermedia & HATEOAS + + + + +
  • + Caching +
  • +
  • Throttling
  • @@ -270,76 +274,83 @@ REST, Hypermedia & HATEOAS + + + + +
  • + XLSX (Binary Spreadsheet Endpoints) +
  • +
  • CSV
  • @@ -866,6 +881,37 @@ In this case you can underspecify the media types it should respond to, by using

    MessagePack

    MessagePack is a fast, efficient binary serialization format. Juan Riaza maintains the djangorestframework-msgpack package which provides MessagePack renderer and parser support for REST framework.

    +

    XLSX (Binary Spreadsheet Endpoints)

    +

    XLSX is the world's most popular binary spreadsheet format. Tim Allen of The Wharton School maintains drf-renderer-xlsx, which renders an endpoint as an XLSX spreadsheet using OpenPyXL, and allows the client to download it. Spreadsheets can be styled on a per-view basis.

    +

    Installation & configuration

    +

    Install using pip.

    +
    $ pip install drf-renderer-xlsx
    +
    +

    Modify your REST framework settings.

    +
    REST_FRAMEWORK = {
    +    ...
    +
    +    'DEFAULT_RENDERER_CLASSES': (
    +        'rest_framework.renderers.JSONRenderer',
    +        'rest_framework.renderers.BrowsableAPIRenderer',
    +        'drf_renderer_xlsx.renderers.XLSXRenderer',
    +    ),
    +}
    +
    +

    To avoid having a file streamed without a filename (which the browser will often default to the filename "download", with no extension), we need to use a mixin to override the Content-Disposition header. If no filename is provided, it will default to export.xlsx. For example:

    +
    from rest_framework.viewsets import ReadOnlyModelViewSet
    +from drf_renderer_xlsx.mixins import XLSXFileMixin
    +from drf_renderer_xlsx.renderers import XLSXRenderer
    +
    +from .models import MyExampleModel
    +from .serializers import MyExampleSerializer
    +
    +class MyExampleViewSet(XLSXFileMixin, ReadOnlyModelViewSet):
    +    queryset = MyExampleModel.objects.all()
    +    serializer_class = MyExampleSerializer
    +    renderer_classes = (XLSXRenderer,)
    +    filename = 'my_export.xlsx'
    +

    CSV

    Comma-separated values are a plain-text tabular data format, that can be easily imported into spreadsheet applications. Mjumbe Poe maintains the djangorestframework-csv package which provides CSV renderer support for REST framework.

    UltraJSON

    diff --git a/api-guide/requests/index.html b/api-guide/requests/index.html index 84927fcef..600fd64fe 100644 --- a/api-guide/requests/index.html +++ b/api-guide/requests/index.html @@ -179,6 +179,10 @@ Permissions +
  • + Caching +
  • +
  • Throttling
  • @@ -270,76 +274,83 @@ REST, Hypermedia & HATEOAS + + + + +
  • + Caching +
  • +
  • Throttling
  • @@ -270,76 +274,83 @@ REST, Hypermedia & HATEOAS + + + + +
  • + Caching +
  • +
  • Throttling
  • @@ -270,76 +274,83 @@ REST, Hypermedia & HATEOAS + + + + +
  • + Caching +
  • +
  • Throttling
  • @@ -270,76 +274,83 @@ REST, Hypermedia & HATEOAS + + + + +
  • + Caching +
  • +
  • Throttling
  • @@ -270,76 +274,83 @@ REST, Hypermedia & HATEOAS + + + +
    +

    This also applies to extra actions for ViewSets:

    +
        class CustomViewSet(viewsets.ModelViewSet):
    +
    +        @action(detail=True, schema=None)
    +        def extra_action(self, request, pk=None):
    +            ...
    +

    Note: For full details on SchemaGenerator plus the AutoSchema and ManualSchema descriptors see the API Reference below.

    @@ -999,13 +1017,13 @@ view docstring as described in the "Schemas as Documentation" section above.

    with the given view. Eg. 'application/json'. May return a blank string for views that do not expect a request body.

    get_path_fields(self, path, method):

    -

    Return a list of coreapi.Link() instances. One for each path parameter in the URL.

    +

    Return a list of coreapi.Field() instances. One for each path parameter in the URL.

    get_serializer_fields(self, path, method)

    -

    Return a list of coreapi.Link() instances. One for each field in the serializer class used by the view.

    +

    Return a list of coreapi.Field() instances. One for each field in the serializer class used by the view.

    get_pagination_fields(self, path, method)

    -

    Return a list of coreapi.Link() instances, as returned by the get_schema_fields() method on any pagination class used by the view.

    +

    Return a list of coreapi.Field() instances, as returned by the get_schema_fields() method on any pagination class used by the view.

    get_filter_fields(self, path, method)

    -

    Return a list of coreapi.Link() instances, as returned by the get_schema_fields() method of any filter classes used by the view.

    +

    Return a list of coreapi.Field() instances, as returned by the get_schema_fields() method of any filter classes used by the view.

    get_manual_fields(self, path, method)

    Return a list of coreapi.Field() instances to be added to or replace generated fields. Defaults to (optional) manual_fields passed to AutoSchema constructor.

    May be overridden to customise manual fields by path or method. For example, a per-method adjustment may look like this:

    diff --git a/api-guide/serializers/index.html b/api-guide/serializers/index.html index d6e4e6059..28cc8e8ff 100644 --- a/api-guide/serializers/index.html +++ b/api-guide/serializers/index.html @@ -179,6 +179,10 @@ Permissions +
  • + Caching +
  • +
  • Throttling
  • @@ -270,76 +274,83 @@ REST, Hypermedia & HATEOAS + + + +
    +
  • + Caching +
  • +
  • Throttling
  • @@ -270,76 +274,83 @@ REST, Hypermedia & HATEOAS + + + + +
  • + Caching +
  • +
  • Throttling
  • @@ -270,76 +274,83 @@ REST, Hypermedia & HATEOAS + + + + +
  • + Caching +
  • +
  • Throttling
  • @@ -270,76 +274,83 @@ REST, Hypermedia & HATEOAS + + + +

    This exposes exactly the same interface as if you were using a requests session directly.

    -
    client = RequestsClient()
    +
    from rest_framework.test import RequestsClient
    +
    +client = RequestsClient()
     response = client.get('http://testserver/users/')
     assert response.status_code == 200
     
    @@ -698,12 +711,12 @@ token in the following request.

    client = RequestsClient()
     
     # Obtain a CSRF token.
    -response = client.get('/homepage/')
    +response = client.get('http://testserver/homepage/')
     assert response.status_code == 200
     csrftoken = response.cookies['csrftoken']
     
     # Interact with the API.
    -response = client.post('/organisations/', json={
    +response = client.post('http://testserver/organisations/', json={
         'name': 'MegaCorp',
         'status': 'active'
     }, headers={'X-CSRFToken': csrftoken})
    diff --git a/api-guide/throttling/index.html b/api-guide/throttling/index.html
    index a9d82654f..9e91dc074 100644
    --- a/api-guide/throttling/index.html
    +++ b/api-guide/throttling/index.html
    @@ -61,7 +61,7 @@
               
    -          
                Search
    @@ -179,6 +179,10 @@
                         Permissions
                       
                       
    +                  
  • + Caching +
  • +
  • Throttling
  • @@ -270,76 +274,83 @@ REST, Hypermedia & HATEOAS + + + + +
  • + Caching +
  • +
  • Throttling
  • @@ -270,76 +274,83 @@ REST, Hypermedia & HATEOAS + + + + +
  • + Caching +
  • +
  • Throttling
  • @@ -270,76 +274,83 @@ REST, Hypermedia & HATEOAS + + + + +
  • + Caching +
  • +
  • Throttling
  • @@ -270,76 +274,83 @@ REST, Hypermedia & HATEOAS + + + + +
  • + Caching +
  • +
  • Throttling
  • @@ -270,76 +274,83 @@ REST, Hypermedia & HATEOAS + + + +

    Rather than writing your own viewsets, you'll often want to use the existing base classes that provide a default set of behavior. For example:

    @@ -557,6 +568,8 @@ urlpatterns = router.urls
  • action - the name of the current action (e.g., list, create).
  • detail - boolean indicating if the current action is configured for a list or detail view.
  • suffix - the display suffix for the viewset type - mirrors the detail attribute.
  • +
  • name - the display name for the viewset. This argument is mutually exclusive to suffix.
  • +
  • description - the display description for the individual view of a viewset.
  • You may inspect these attributes to adjust behaviour based on the current action. For example, you could restrict permissions to everything except the list action similar to this:

    def get_permissions(self):
    @@ -585,7 +598,7 @@ class UserViewSet(viewsets.ModelViewSet):
         queryset = User.objects.all()
         serializer_class = UserSerializer
     
    -    @action(methods=['post'], detail=True)
    +    @action(detail=True, methods=['post'])
         def set_password(self, request, pk=None):
             user = self.get_object()
             serializer = PasswordSerializer(data=request.data)
    @@ -610,17 +623,30 @@ class UserViewSet(viewsets.ModelViewSet):
             return Response(serializer.data)
     

    The decorator can additionally take extra arguments that will be set for the routed view only. For example:

    -
        @action(methods=['post'], detail=True, permission_classes=[IsAdminOrIsSelf])
    +
        @action(detail=True, methods=['post'], permission_classes=[IsAdminOrIsSelf])
         def set_password(self, request, pk=None):
            ...
     

    These decorator will route GET requests by default, but may also accept other HTTP methods by setting the methods argument. For example:

    -
        @action(methods=['post', 'delete'], detail=True)
    +
        @action(detail=True, 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/$

    To view all extra actions, call the .get_extra_actions() method.

    +

    Routing additional HTTP methods for extra actions

    +

    Extra actions can be mapped to different ViewSet methods. For example, the above password set/unset methods could be consolidated into a single route. Note that additional mappings do not accept arguments.

    +
        @action(detail=True, methods=['put'], name='Change Password')
    +    def password(self, request, pk=None):
    +        """Update the user's password."""
    +        ...
    +
    +    @password.mapping.delete
    +    def delete_password(self, request, pk=None):
    +        """Delete the user's password."""
    +        ...
    +
    +

    Reversing action URLs

    If you need to get the URL of an action, use the .reverse_action() method. This is a convenience wrapper for reverse(), automatically passing the view's request object and prepending the url_name with the .basename attribute.

    Note that the basename is provided by the router during ViewSet registration. If you are not using a router, then you must provide the basename argument to the .as_view() method.

    @@ -668,7 +694,7 @@ class UserViewSet(viewsets.ModelViewSet): def get_queryset(self): return self.request.user.accounts.all()
    -

    Note however that upon removal of the queryset property from your ViewSet, any associated router will be unable to derive the base_name of your Model automatically, and so you will have to specify the base_name kwarg as part of your router registration.

    +

    Note however that upon removal of the queryset property from your ViewSet, any associated router will be unable to derive the basename of your Model automatically, and so you will have to specify the basename kwarg as part of your router registration.

    Also note that although this class provides the complete set of create/list/retrieve/update/destroy actions by default, you can restrict the available operations by using the standard permission classes.

    ReadOnlyModelViewSet

    The ReadOnlyModelViewSet class also inherits from GenericAPIView. As with ModelViewSet it also includes implementations for various actions, but unlike ModelViewSet only provides the 'read-only' actions, .list() and .retrieve().

    diff --git a/topics/3.0-announcement/index.html b/community/3.0-announcement/index.html similarity index 98% rename from topics/3.0-announcement/index.html rename to community/3.0-announcement/index.html index 4cec4b64b..ce3030bdb 100644 --- a/topics/3.0-announcement/index.html +++ b/community/3.0-announcement/index.html @@ -6,7 +6,7 @@ 3.0 Announcement - Django REST framework - + @@ -58,10 +58,10 @@

    Internationalization

    -

    REST framework now includes a built-in set of translations, and supports internationalized error responses. This allows you to either change the default language, or to allow clients to specify the language via the Accept-Language header.

    +

    REST framework now includes a built-in set of translations, and supports internationalized error responses. This allows you to either change the default language, or to allow clients to specify the language via the Accept-Language header.

    You can change the default language by using the standard Django LANGUAGE_CODE setting:

    LANGUAGE_CODE = "es-es"
     
    @@ -527,7 +538,7 @@ Host: example.org ('en', _('English')), ]
    -

    For more details, see the internationalization documentation.

    +

    For more details, see the internationalization documentation.

    Many thanks to Craig Blaszczyk for helping push this through.


    New field types

    diff --git a/topics/3.2-announcement/index.html b/community/3.2-announcement/index.html similarity index 95% rename from topics/3.2-announcement/index.html rename to community/3.2-announcement/index.html index 0382eaade..7a4388df6 100644 --- a/topics/3.2-announcement/index.html +++ b/community/3.2-announcement/index.html @@ -6,7 +6,7 @@ 3.2 Announcement - Django REST framework - + @@ -58,10 +58,10 @@