diff --git a/.travis.yml b/.travis.yml index 76adf1a60..a0d72e3d6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,26 +1,30 @@ language: python cache: pip -python: - - "2.7" - - "3.4" - - "3.5" - sudo: false -env: - - DJANGO=1.11 - - DJANGO=2.0 - - DJANGO=2.1 - - DJANGO=master - matrix: fast_finish: true include: - - { python: "3.6", env: DJANGO=master } + - { python: "2.7", env: DJANGO=1.11 } + + - { python: "3.4", env: DJANGO=1.11 } + - { python: "3.4", env: DJANGO=2.0 } + + - { python: "3.5", env: DJANGO=1.11 } + - { python: "3.5", env: DJANGO=2.0 } + - { python: "3.5", env: DJANGO=2.1 } + - { python: "3.5", env: DJANGO=master } + - { python: "3.6", env: DJANGO=1.11 } - { python: "3.6", env: DJANGO=2.0 } - { python: "3.6", env: DJANGO=2.1 } + - { python: "3.6", env: DJANGO=master } + + - { python: "3.7", env: DJANGO=2.0, dist: xenial, sudo: true } + - { python: "3.7", env: DJANGO=2.1, dist: xenial, sudo: true } + - { python: "3.7", env: DJANGO=master, dist: xenial, sudo: true } + - { python: "3.6", env: TOXENV=base } - { python: "2.7", env: TOXENV=lint } - { python: "2.7", env: TOXENV=docs } @@ -29,22 +33,15 @@ matrix: env: TOXENV=dist script: - python setup.py bdist_wheel + - rm -r djangorestframework.egg-info # see #6139 - tox --installpkg ./dist/djangorestframework-*.whl - tox # test sdist - exclude: - - { python: "2.7", env: DJANGO=master } - - { python: "2.7", env: DJANGO=2.0 } - - { python: "2.7", env: DJANGO=2.1 } - - { python: "3.4", env: DJANGO=master } - - { python: "3.4", env: DJANGO=2.1 } - allow_failures: - env: DJANGO=master - - env: DJANGO=2.1 install: - - pip install tox tox-travis + - pip install tox tox-venv tox-travis script: - tox diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index 55b3e531b..8f2391d29 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -3,7 +3,7 @@ - [ ] I have verified that that issue exists against the `master` branch of Django REST framework. - [ ] I have searched for similar issues in both open and closed tickets and cannot find a duplicate. - [ ] This is not a usage question. (Those should be directed to the [discussion group](https://groups.google.com/forum/#!forum/django-rest-framework) instead.) -- [ ] This cannot be dealt with as a third party library. (We prefer new functionality to be [in the form of third party libraries](http://www.django-rest-framework.org/topics/third-party-resources/#about-third-party-packages) where possible.) +- [ ] This cannot be dealt with as a third party library. (We prefer new functionality to be [in the form of third party libraries](https://www.django-rest-framework.org/topics/third-party-resources/#about-third-party-packages) where possible.) - [ ] I have reduced the issue to the simplest possible case. - [ ] I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.) diff --git a/LICENSE.md b/LICENSE.md index 03213cbd6..3dea39c36 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ # License -Copyright © 2011-present, [Encode OSS Ltd](http://www.encode.io/). +Copyright © 2011-present, [Encode OSS Ltd](https://www.encode.io/). All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/README.md b/README.md index eebcfe13f..f49593bbd 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ **Awesome web-browsable Web APIs.** -Full documentation for the project is available at [http://www.django-rest-framework.org][docs]. +Full documentation for the project is available at [https://www.django-rest-framework.org/][docs]. --- @@ -22,11 +22,13 @@ The initial aim is to provide a single full-time position on REST framework. [![][rover-img]][rover-url] [![][sentry-img]][sentry-url] [![][stream-img]][stream-url] -[![][machinalis-img]][machinalis-url] [![][rollbar-img]][rollbar-url] [![][cadre-img]][cadre-url] +[![][load-impact-img]][load-impact-url] +[![][kloudless-img]][kloudless-url] +[![][auklet-img]][auklet-url] -Many thanks to all our [wonderful sponsors][sponsors], and in particular to our premium backers, [Rover][rover-url], [Sentry][sentry-url], [Stream][stream-url], [Machinalis][machinalis-url], [Rollbar][rollbar-url], and [Cadre][cadre-url]. +Many thanks to all our [wonderful sponsors][sponsors], and in particular to our premium backers, [Rover][rover-url], [Sentry][sentry-url], [Stream][stream-url], [Rollbar][rollbar-url], [Cadre][cadre-url], [Load Impact][load-impact-url], [Kloudless][kloudless-url], and [Auklet][auklet-url]. --- @@ -52,8 +54,8 @@ There is a live example API for testing purposes, [available here][sandbox]. # Requirements -* Python (2.7, 3.4, 3.5, 3.6) -* Django (1.11, 2.0) +* Python (2.7, 3.4, 3.5, 3.6, 3.7) +* Django (1.11, 2.0, 2.1) # Installation @@ -76,7 +78,7 @@ Startup up a new project like so... pip install django pip install djangorestframework - django-admin.py startproject example . + django-admin startproject example . ./manage.py migrate ./manage.py createsuperuser @@ -142,14 +144,14 @@ You can now open the API in your browser at `http://127.0.0.1:8000/`, and view y You can also interact with the API using command line tools such as [`curl`](https://curl.haxx.se/). For example, to list the users endpoint: $ curl -H 'Accept: application/json; indent=4' -u admin:password http://127.0.0.1:8000/users/ - [ - { - "url": "http://127.0.0.1:8000/users/1/", - "username": "admin", - "email": "admin@example.com", - "is_staff": true, - } - ] + [ + { + "url": "http://127.0.0.1:8000/users/1/", + "username": "admin", + "email": "admin@example.com", + "is_staff": true, + } + ] Or to create a new user: @@ -163,7 +165,7 @@ Or to create a new user: # Documentation & Support -Full documentation for the project is available at [http://www.django-rest-framework.org][docs]. +Full documentation for the project is available at [https://www.django-rest-framework.org/][docs]. For questions and support, use the [REST framework discussion group][group], or `#restframework` on freenode IRC. @@ -191,28 +193,32 @@ Send a description of the issue via email to [rest-framework-security@googlegrou [rover-img]: https://raw.githubusercontent.com/encode/django-rest-framework/master/docs/img/premium/rover-readme.png [sentry-img]: https://raw.githubusercontent.com/encode/django-rest-framework/master/docs/img/premium/sentry-readme.png [stream-img]: https://raw.githubusercontent.com/encode/django-rest-framework/master/docs/img/premium/stream-readme.png -[machinalis-img]: https://raw.githubusercontent.com/encode/django-rest-framework/master/docs/img/premium/machinalis-readme.png [rollbar-img]: https://raw.githubusercontent.com/encode/django-rest-framework/master/docs/img/premium/rollbar-readme.png [cadre-img]: https://raw.githubusercontent.com/encode/django-rest-framework/master/docs/img/premium/cadre-readme.png +[load-impact-img]: https://raw.githubusercontent.com/encode/django-rest-framework/master/docs/img/premium/load-impact-readme.png +[kloudless-img]: https://raw.githubusercontent.com/encode/django-rest-framework/master/docs/img/premium/kloudless-readme.png +[auklet-img]: https://raw.githubusercontent.com/encode/django-rest-framework/master/docs/img/premium/auklet-readme.png [rover-url]: http://jobs.rover.com/ [sentry-url]: https://getsentry.com/welcome/ [stream-url]: https://getstream.io/try-the-api/?utm_source=drf&utm_medium=banner&utm_campaign=drf -[machinalis-url]: https://hello.machinalis.co.uk/ [rollbar-url]: https://rollbar.com/ [cadre-url]: https://cadre.com/ +[load-impact-url]: https://loadimpact.com/?utm_campaign=Sponsorship%20links&utm_source=drf&utm_medium=drf +[kloudless-url]: https://hubs.ly/H0f30Lf0 +[auklet-url]: https://auklet.io/ -[oauth1-section]: http://www.django-rest-framework.org/api-guide/authentication/#django-rest-framework-oauth -[oauth2-section]: http://www.django-rest-framework.org/api-guide/authentication/#django-oauth-toolkit -[serializer-section]: http://www.django-rest-framework.org/api-guide/serializers/#serializers -[modelserializer-section]: http://www.django-rest-framework.org/api-guide/serializers/#modelserializer -[functionview-section]: http://www.django-rest-framework.org/api-guide/views/#function-based-views -[generic-views]: http://www.django-rest-framework.org/api-guide/generic-views/ -[viewsets]: http://www.django-rest-framework.org/api-guide/viewsets/ -[routers]: http://www.django-rest-framework.org/api-guide/routers/ -[serializers]: http://www.django-rest-framework.org/api-guide/serializers/ -[authentication]: http://www.django-rest-framework.org/api-guide/authentication/ -[image]: http://www.django-rest-framework.org/img/quickstart.png +[oauth1-section]: https://www.django-rest-framework.org/api-guide/authentication/#django-rest-framework-oauth +[oauth2-section]: https://www.django-rest-framework.org/api-guide/authentication/#django-oauth-toolkit +[serializer-section]: https://www.django-rest-framework.org/api-guide/serializers/#serializers +[modelserializer-section]: https://www.django-rest-framework.org/api-guide/serializers/#modelserializer +[functionview-section]: https://www.django-rest-framework.org/api-guide/views/#function-based-views +[generic-views]: https://www.django-rest-framework.org/api-guide/generic-views/ +[viewsets]: https://www.django-rest-framework.org/api-guide/viewsets/ +[routers]: https://www.django-rest-framework.org/api-guide/routers/ +[serializers]: https://www.django-rest-framework.org/api-guide/serializers/ +[authentication]: https://www.django-rest-framework.org/api-guide/authentication/ +[image]: https://www.django-rest-framework.org/img/quickstart.png -[docs]: http://www.django-rest-framework.org/ +[docs]: https://www.django-rest-framework.org/ [security-mail]: mailto:rest-framework-security@googlegroups.com diff --git a/codecov.yml b/codecov.yml index edccd5c35..c2336342e 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,8 +1,11 @@ coverage: - status: - project: false - patch: true - changes: true + precision: 2 + round: down + range: "80...100" -comment: - layout: "diff" + status: + project: yes + patch: no + changes: no + +comment: off diff --git a/docs/api-guide/authentication.md b/docs/api-guide/authentication.md index e10e3109a..0776b6340 100644 --- a/docs/api-guide/authentication.md +++ b/docs/api-guide/authentication.md @@ -137,7 +137,7 @@ You'll also need to create tokens for your users. from rest_framework.authtoken.models import Token token = Token.objects.create(user=...) - print token.key + print(token.key) For clients to authenticate, the token key should be included in the `Authorization` HTTP header. The key should be prefixed by the string literal "Token", with whitespace separating the two strings. For example: @@ -397,7 +397,7 @@ HTTP digest authentication is a widely implemented scheme that was intended to r ## 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][blimp] maintains the [djangorestframework-jwt][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][djangorestframework-simplejwt] which provides different features as well as a pluggable token blacklist app. +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. A package for JWT authentication is [djangorestframework-simplejwt][djangorestframework-simplejwt] which provides some features as well as a pluggable token blacklist app. ## Hawk HTTP Authentication @@ -445,8 +445,6 @@ HTTP Signature (currently a [IETF draft][http-signature-ietf-draft]) provides a [django-oauth-toolkit]: https://github.com/evonove/django-oauth-toolkit [evonove]: https://github.com/evonove/ [oauthlib]: https://github.com/idan/oauthlib -[blimp]: https://github.com/GetBlimp -[djangorestframework-jwt]: https://github.com/GetBlimp/django-rest-framework-jwt [djangorestframework-simplejwt]: https://github.com/davesque/django-rest-framework-simplejwt [etoccalino]: https://github.com/etoccalino/ [djangorestframework-httpsignature]: https://github.com/etoccalino/django-rest-framework-httpsignature diff --git a/docs/api-guide/filtering.md b/docs/api-guide/filtering.md index e405535ba..84c6d8d63 100644 --- a/docs/api-guide/filtering.md +++ b/docs/api-guide/filtering.md @@ -285,6 +285,12 @@ The `ordering` attribute may be either a string or a list/tuple of strings. The `DjangoObjectPermissionsFilter` is intended to be used together with the [`django-guardian`][guardian] package, with custom `'view'` permissions added. The filter will ensure that querysets only returns objects for which the user has the appropriate view permission. +--- + +**Note:** This filter has been deprecated as of version 3.9 and moved to the 3rd-party [`djangorestframework-guardian` package][django-rest-framework-guardian]. + +--- + If you're using `DjangoObjectPermissionsFilter`, you'll probably also want to add an appropriate object permissions class, to ensure that users can only operate on instances if they have the appropriate object permissions. The easiest way to do this is to subclass `DjangoObjectPermissions` and add `'view'` permissions to the `perms_map` attribute. A complete example using both `DjangoObjectPermissionsFilter` and `DjangoObjectPermissions` might look something like this. @@ -388,6 +394,7 @@ The [djangorestframework-word-filter][django-rest-framework-word-search-filter] [view-permissions-blogpost]: https://blog.nyaruka.com/adding-a-view-permission-to-django-models [search-django-admin]: https://docs.djangoproject.com/en/stable/ref/contrib/admin/#django.contrib.admin.ModelAdmin.search_fields [django-rest-framework-filters]: https://github.com/philipn/django-rest-framework-filters +[django-rest-framework-guardian]: https://github.com/rpkilby/django-rest-framework-guardian [django-rest-framework-word-search-filter]: https://github.com/trollknurr/django-rest-framework-word-search-filter [django-url-filter]: https://github.com/miki725/django-url-filter [drf-url-filter]: https://github.com/manjitkumar/drf-url-filters diff --git a/docs/api-guide/format-suffixes.md b/docs/api-guide/format-suffixes.md index 05dde47f2..629f003f3 100644 --- a/docs/api-guide/format-suffixes.md +++ b/docs/api-guide/format-suffixes.md @@ -90,4 +90,4 @@ It is actually a misconception. For example, take the following quote from Roy The quote does not mention Accept headers, but it does make it clear that format suffixes should be considered an acceptable pattern. [cite]: http://tech.groups.yahoo.com/group/rest-discuss/message/5857 -[cite2]: http://tech.groups.yahoo.com/group/rest-discuss/message/14844 +[cite2]: https://groups.yahoo.com/neo/groups/rest-discuss/conversations/topics/14844 diff --git a/docs/api-guide/metadata.md b/docs/api-guide/metadata.md index affeea61c..a3ba9ac20 100644 --- a/docs/api-guide/metadata.md +++ b/docs/api-guide/metadata.md @@ -117,5 +117,5 @@ If you wish to do so, it also provides an exporter that can export those schema [cite]: https://tools.ietf.org/html/rfc7231#section-4.3.7 [no-options]: https://www.mnot.net/blog/2012/10/29/NO_OPTIONS -[json-schema]: http://json-schema.org/ +[json-schema]: https://json-schema.org/ [drf-schema-adapter]: https://github.com/drf-forms/drf-schema-adapter diff --git a/docs/api-guide/pagination.md b/docs/api-guide/pagination.md index c1e487c67..7ae351a7f 100644 --- a/docs/api-guide/pagination.md +++ b/docs/api-guide/pagination.md @@ -46,7 +46,7 @@ If you want to modify particular aspects of the pagination style, you'll want to page_size_query_param = 'page_size' max_page_size = 1000 -You can then apply your new style to a view using the `.pagination_class` attribute: +You can then apply your new style to a view using the `pagination_class` attribute: class BillingRecordsView(generics.ListAPIView): queryset = Billing.objects.all() @@ -319,5 +319,5 @@ The [`django-rest-framework-link-header-pagination` package][drf-link-header-pag [paginate-by-max-mixin]: https://chibisov.github.io/drf-extensions/docs/#paginatebymaxmixin [drf-proxy-pagination]: https://github.com/tuffnatty/drf-proxy-pagination [drf-link-header-pagination]: https://github.com/tbeadle/django-rest-framework-link-header-pagination -[disqus-cursor-api]: http://cra.mr/2011/03/08/building-cursors-for-the-disqus-api +[disqus-cursor-api]: https://cra.mr/2011/03/08/building-cursors-for-the-disqus-api [float_cursor_pagination_example]: https://gist.github.com/keturn/8bc88525a183fd41c73ffb729b8865be#file-fpcursorpagination-py diff --git a/docs/api-guide/permissions.md b/docs/api-guide/permissions.md index f5fc214cd..102c6ea98 100644 --- a/docs/api-guide/permissions.md +++ b/docs/api-guide/permissions.md @@ -102,6 +102,27 @@ Or, if you're using the `@api_view` decorator with function based views. __Note:__ when you set new permission classes through class attribute or decorators you're telling the view to ignore the default list set over the __settings.py__ file. +Provided they inherit from `rest_framework.permissions.BasePermission`, permissions can be composed using standard Python bitwise operators. For example, `IsAuthenticatedOrReadOnly` could be written: + + from rest_framework.permissions import BasePermission, IsAuthenticated + from rest_framework.response import Response + from rest_framework.views import APIView + + class ReadOnly(BasePermission): + def has_permission(self, request, view): + return request.method in SAFE_METHODS + + class ExampleView(APIView): + permission_classes = (IsAuthenticated|ReadOnly) + + def get(self, request, format=None): + content = { + 'status': 'request was permitted' + } + return Response(content) + +__Note:__ it only supports & -and- and | -or-. + --- # API Reference @@ -168,9 +189,7 @@ As with `DjangoModelPermissions` you can use custom model permissions by overrid --- -**Note**: If you need object level `view` permissions for `GET`, `HEAD` and `OPTIONS` requests, you'll want to consider also adding the `DjangoObjectPermissionsFilter` class to ensure that list endpoints only return results including objects for which the user has appropriate view permissions. - ---- +**Note**: If you need object level `view` permissions for `GET`, `HEAD` and `OPTIONS` requests and are using django-guardian for your object-level permissions backend, you'll want to consider using the `DjangoObjectPermissionsFilter` class provided by the [`djangorestframework-guardian` package][django-rest-framework-guardian]. It ensures that list endpoints only return results including objects for which the user has appropriate view permissions. --- @@ -287,3 +306,4 @@ The [Django Rest Framework Role Filters][django-rest-framework-role-filters] pac [django-rest-framework-roles]: https://github.com/computer-lab/django-rest-framework-roles [django-rest-framework-api-key]: https://github.com/manosim/django-rest-framework-api-key [django-rest-framework-role-filters]: https://github.com/allisson/django-rest-framework-role-filters +[django-rest-framework-guardian]: https://github.com/rpkilby/django-rest-framework-guardian diff --git a/docs/api-guide/relations.md b/docs/api-guide/relations.md index 02ecf5b12..6a865b7d1 100644 --- a/docs/api-guide/relations.md +++ b/docs/api-guide/relations.md @@ -594,7 +594,7 @@ The [rest-framework-generic-relations][drf-nested-relations] library provides re [cite]: https://lwn.net/Articles/193245/ [reverse-relationships]: https://docs.djangoproject.com/en/stable/topics/db/queries/#following-relationships-backward -[routers]: http://www.django-rest-framework.org/api-guide/routers#defaultrouter +[routers]: https://www.django-rest-framework.org/api-guide/routers#defaultrouter [generic-relations]: https://docs.djangoproject.com/en/stable/ref/contrib/contenttypes/#id1 [drf-nested-routers]: https://github.com/alanjds/drf-nested-routers [drf-nested-relations]: https://github.com/Ian-Foote/rest-framework-generic-relations diff --git a/docs/api-guide/renderers.md b/docs/api-guide/renderers.md index d547a7bbf..a43f4be8a 100644 --- a/docs/api-guide/renderers.md +++ b/docs/api-guide/renderers.md @@ -457,6 +457,43 @@ Modify your REST framework settings. [MessagePack][messagepack] is a fast, efficient binary serialization format. [Juan Riaza][juanriaza] maintains the [djangorestframework-msgpack][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][flipperpa] of [The Wharton School][wharton] maintains [drf-renderer-xlsx][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][mjumbewu] maintains the [djangorestframework-csv][djangorestframework-csv] package which provides CSV renderer support for REST framework. @@ -484,19 +521,22 @@ Comma-separated values are a plain-text tabular data format, that can be easily [browser-accept-headers]: http://www.gethifi.com/blog/browser-rest-http-accept-headers [testing]: testing.md [HATEOAS]: http://timelessrepo.com/haters-gonna-hateoas -[quote]: http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven +[quote]: https://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven [application/vnd.github+json]: https://developer.github.com/v3/media/ [application/vnd.collection+json]: http://www.amundsen.com/media-types/collection/ [django-error-views]: https://docs.djangoproject.com/en/stable/topics/http/views/#customizing-error-views [rest-framework-jsonp]: https://jpadilla.github.io/django-rest-framework-jsonp/ [cors]: https://www.w3.org/TR/cors/ -[cors-docs]: http://www.django-rest-framework.org/topics/ajax-csrf-cors/ +[cors-docs]: https://www.django-rest-framework.org/topics/ajax-csrf-cors/ [jsonp-security]: https://stackoverflow.com/questions/613962/is-jsonp-safe-to-use [rest-framework-yaml]: https://jpadilla.github.io/django-rest-framework-yaml/ [rest-framework-xml]: https://jpadilla.github.io/django-rest-framework-xml/ [messagepack]: https://msgpack.org/ [juanriaza]: https://github.com/juanriaza [mjumbewu]: https://github.com/mjumbewu +[flipperpa]: https://githuc.com/flipperpa +[wharton]: https://github.com/wharton +[drf-renderer-xlsx]: https://github.com/wharton/drf-renderer-xlsx [vbabiy]: https://github.com/vbabiy [rest-framework-yaml]: https://jpadilla.github.io/django-rest-framework-yaml/ [rest-framework-xml]: https://jpadilla.github.io/django-rest-framework-xml/ diff --git a/docs/api-guide/requests.md b/docs/api-guide/requests.md index 83a38d1c3..35b976c66 100644 --- a/docs/api-guide/requests.md +++ b/docs/api-guide/requests.md @@ -90,7 +90,7 @@ You won't typically need to access this property. --- -**Note:** You may see a `WrappedAttributeError` raised when calling the `.user` or `.auth` properties. These errors originate from an authenticator as a standard `AttributeError`, however it's necessary that they be re-raised as a different exception type in order to prevent them from being suppressed by the outer property access. Python will not recognize that the `AttributeError` orginates from the authenticator and will instaed assume that the request object does not have a `.user` or `.auth` property. The authenticator will need to be fixed. +**Note:** You may see a `WrappedAttributeError` raised when calling the `.user` or `.auth` properties. These errors originate from an authenticator as a standard `AttributeError`, however it's necessary that they be re-raised as a different exception type in order to prevent them from being suppressed by the outer property access. Python will not recognize that the `AttributeError` orginates from the authenticator and will instead assume that the request object does not have a `.user` or `.auth` property. The authenticator will need to be fixed. --- diff --git a/docs/api-guide/routers.md b/docs/api-guide/routers.md index d3ebd6866..09c6c39cb 100644 --- a/docs/api-guide/routers.md +++ b/docs/api-guide/routers.md @@ -325,7 +325,7 @@ The [wq.db package][wq.db] provides an advanced [ModelRouter][wq.db-router] clas The [`DRF-extensions` package][drf-extensions] provides [routers][drf-extensions-routers] for creating [nested viewsets][drf-extensions-nested-viewsets], [collection level controllers][drf-extensions-collection-level-controllers] with [customizable endpoint names][drf-extensions-customizable-endpoint-names]. -[cite]: http://guides.rubyonrails.org/routing.html +[cite]: https://guides.rubyonrails.org/routing.html [route-decorators]: viewsets.md#marking-extra-actions-for-routing [drf-nested-routers]: https://github.com/alanjds/drf-nested-routers [wq.db]: https://wq.io/wq.db diff --git a/docs/api-guide/schemas.md b/docs/api-guide/schemas.md index 6ad259588..8a6688378 100644 --- a/docs/api-guide/schemas.md +++ b/docs/api-guide/schemas.md @@ -10,12 +10,50 @@ API schemas are a useful tool that allow for a range of use cases, including generating reference documentation, or driving dynamic client libraries that can interact with your API. -## Install Core API +## Install Core API & PyYAML You'll need to install the `coreapi` package in order to add schema support -for REST framework. +for REST framework. You probably also want to install `pyyaml`, so that you +can render the schema into the commonly used YAML-based OpenAPI format. - pip install coreapi + pip install coreapi pyyaml + +## Quickstart + +There are two different ways you can serve a schema description for you API. + +### Generating a schema with the `generateschema` management command + +To generate a static API schema, use the `generateschema` management command. + +```shell +$ python manage.py generateschema > schema.yml +``` + +Once you've generated a schema in this way you can annotate it with any +additional information that cannot be automatically inferred by the schema +generator. + +You might want to check your API schema into version control and update it +with each new release, or serve the API schema from your site's static media. + +### Adding a view with `get_schema_view` + +To add a dynamically generated schema view to your API, use `get_schema_view`. + +```python +from rest_framework.schemas import get_schema_view + +schema_view = get_schema_view(title="Example API") + +urlpatterns = [ + url('^schema$', schema_view), + ... +] +``` + +See below [for more details](#the-get_schema_view-shortcut) on customizing a +dynamically generated schema view. ## Internal schema representation @@ -71,38 +109,19 @@ endpoint: In order to be presented in an HTTP response, the internal representation has to be rendered into the actual bytes that are used in the response. +REST framework includes a few different renderers that you can use for +encoding the API schema. + +* `renderers.OpenAPIRenderer` - Renders into YAML-based [OpenAPI][openapi], the most widely used API schema format. +* `renderers.JSONOpenAPIRenderer` - Renders into JSON-based [OpenAPI][openapi]. +* `renderers.CoreJSONRenderer` - Renders into [Core JSON][corejson], a format designed for +use with the `coreapi` client library. + + [Core JSON][corejson] is designed as a canonical format for use with Core API. REST framework includes a renderer class for handling this media type, which is available as `renderers.CoreJSONRenderer`. -### Alternate schema formats - -Other schema formats such as [Open API][open-api] ("Swagger"), -[JSON HyperSchema][json-hyperschema], or [API Blueprint][api-blueprint] can also -be supported by implementing a custom renderer class that handles converting a -`Document` instance into a bytestring representation. - -If there is a Core API codec package that supports encoding into the format you -want to use then implementing the renderer class can be done by using the codec. - -#### Example - -For example, the `openapi_codec` package provides support for encoding or decoding -to the Open API ("Swagger") format: - - from rest_framework import renderers - from openapi_codec import OpenAPICodec - - class SwaggerRenderer(renderers.BaseRenderer): - media_type = 'application/openapi+json' - format = 'swagger' - - def render(self, data, media_type=None, renderer_context=None): - codec = OpenAPICodec() - return codec.dump(data) - - - ## Schemas vs Hypermedia @@ -146,7 +165,7 @@ example above. Automatic schema generation is provided by the `SchemaGenerator` class. -`SchemaGenerator` processes a list of routed URL pattterns and compiles the +`SchemaGenerator` processes a list of routed URL patterns and compiles the appropriately structured Core API Document. Basic usage is just to provide the title for your schema and call @@ -325,13 +344,12 @@ ROOT_URLCONF setting. May be used to pass the set of renderer classes that can be used to render the API root endpoint. from rest_framework.schemas import get_schema_view - from rest_framework.renderers import CoreJSONRenderer - from my_custom_package import APIBlueprintRenderer + from rest_framework.renderers import JSONOpenAPIRenderer schema_view = get_schema_view( title='Server Monitoring API', url='https://www.example.org/api/', - renderer_classes=[CoreJSONRenderer, APIBlueprintRenderer] + renderer_classes=[JSONOpenAPIRenderer] ) #### `patterns` @@ -364,7 +382,6 @@ Defaults to `settings.DEFAULT_AUTHENTICATION_CLASSES` May be used to specify the list of permission classes that will apply to the schema endpoint. Defaults to `settings.DEFAULT_PERMISSION_CLASSES` - ## Using an explicit schema view If you need a little more control than the `get_schema_view()` shortcut gives you, @@ -386,7 +403,7 @@ return the schema. generator = schemas.SchemaGenerator(title='Bookings API') @api_view() - @renderer_classes([renderers.CoreJSONRenderer]) + @renderer_classes([renderers.OpenAPIRenderer]) def schema_view(request): schema = generator.get_schema(request) return response.Response(schema) @@ -408,7 +425,7 @@ In order to present a schema with endpoints filtered by user permissions, you need to pass the `request` argument to the `get_schema()` method, like so: @api_view() - @renderer_classes([renderers.CoreJSONRenderer]) + @renderer_classes([renderers.OpenAPIRenderer]) def schema_view(request): generator = schemas.SchemaGenerator(title='Bookings API') return response.Response(generator.get_schema(request=request)) @@ -432,21 +449,10 @@ representation. ) @api_view() - @renderer_classes([renderers.CoreJSONRenderer]) + @renderer_classes([renderers.OpenAPIRenderer]) def schema_view(request): return response.Response(schema) -## Static schema file - -A final option is to write your API schema as a static file, using one -of the available formats, such as Core JSON or Open API. - -You could then either: - -* Write a schema definition as a static file, and [serve the static file directly][static-files]. -* Write a schema definition that is loaded using `Core API`, and then - rendered to one of many available formats, depending on the client request. - --- # Schemas as documentation @@ -535,7 +541,7 @@ Arguments: Returns a `coreapi.Document` instance that represents the API schema. @api_view - @renderer_classes([renderers.CoreJSONRenderer]) + @renderer_classes([renderers.OpenAPIRenderer]) def schema_view(request): generator = schemas.SchemaGenerator(title='Bookings API') return Response(generator.get_schema()) @@ -818,7 +824,7 @@ A short description of the meaning and intended usage of the input field. ## drf-yasg - Yet Another Swagger Generator -[drf-yasg][drf-yasg] generates [OpenAPI][open-api] documents suitable for code generation - nested schemas, +[drf-yasg][drf-yasg] generates [OpenAPI][open-api] documents suitable for code generation - nested schemas, named models, response bodies, enum/pattern/min/max validators, form parameters, etc. @@ -829,12 +835,12 @@ in [OpenAPI][open-api] format. [cite]: https://blog.heroku.com/archives/2014/1/8/json_schema_for_heroku_platform_api -[coreapi]: http://www.coreapi.org/ -[corejson]: http://www.coreapi.org/specification/encoding/#core-json-encoding +[coreapi]: https://www.coreapi.org/ +[corejson]: https://www.coreapi.org/specification/encoding/#core-json-encoding [drf-yasg]: https://github.com/axnsan12/drf-yasg/ [open-api]: https://openapis.org/ [drf-openapi]: https://github.com/limdauto/drf_openapi -[json-hyperschema]: http://json-schema.org/latest/json-schema-hypermedia.html +[json-hyperschema]: https://json-schema.org/latest/json-schema-hypermedia.html [api-blueprint]: https://apiblueprint.org/ [static-files]: https://docs.djangoproject.com/en/stable/howto/static-files/ [named-arguments]: https://docs.djangoproject.com/en/stable/topics/http/urls/#named-groups diff --git a/docs/api-guide/serializers.md b/docs/api-guide/serializers.md index 07921f2d9..19501718e 100644 --- a/docs/api-guide/serializers.md +++ b/docs/api-guide/serializers.md @@ -57,10 +57,10 @@ At this point we've translated the model instance into Python native datatypes. Deserialization is similar. First we parse a stream into Python native datatypes... - from django.utils.six import BytesIO + import io from rest_framework.parsers import JSONParser - stream = BytesIO(json) + stream = io.BytesIO(json) data = JSONParser().parse(stream) ...then we restore those native datatypes into a dictionary of validated data. @@ -1030,7 +1030,7 @@ Similar to Django forms, you can extend and reuse serializers through inheritanc class MyBaseSerializer(Serializer): my_field = serializers.CharField() - def validate_my_field(self): + def validate_my_field(self, value): ... class MySerializer(MyBaseSerializer): diff --git a/docs/api-guide/testing.md b/docs/api-guide/testing.md index a6ecc7557..9134bd08e 100644 --- a/docs/api-guide/testing.md +++ b/docs/api-guide/testing.md @@ -119,7 +119,7 @@ Extends [Django's existing `Client` class][client]. ## Making requests -The `APIClient` class supports the same request interface as Django's standard `Client` class. This means the that standard `.get()`, `.post()`, `.put()`, `.patch()`, `.delete()`, `.head()` and `.options()` methods are all available. For example: +The `APIClient` class supports the same request interface as Django's standard `Client` class. This means that the standard `.get()`, `.post()`, `.put()`, `.patch()`, `.delete()`, `.head()` and `.options()` methods are all available. For example: from rest_framework.test import APIClient diff --git a/docs/api-guide/validators.md b/docs/api-guide/validators.md index 925f67206..3b50442cc 100644 --- a/docs/api-guide/validators.md +++ b/docs/api-guide/validators.md @@ -275,7 +275,7 @@ A validator may be any callable that raises a `serializers.ValidationError` on f You can specify custom field-level validation by adding `.validate_` methods to your `Serializer` subclass. This is documented in the -[Serializer docs](http://www.django-rest-framework.org/api-guide/serializers/#field-level-validation) +[Serializer docs](https://www.django-rest-framework.org/api-guide/serializers/#field-level-validation) ## Class-based diff --git a/docs/api-guide/viewsets.md b/docs/api-guide/viewsets.md index d98f518b3..e7cf4d48f 100644 --- a/docs/api-guide/viewsets.md +++ b/docs/api-guide/viewsets.md @@ -127,7 +127,7 @@ You may inspect these attributes to adjust behaviour based on the current action ## Marking extra actions for routing -If you have ad-hoc methods that should be routable, you can mark them as such with the `@action` decorator. Like regular actions, extra actions may be intended for either a list of objects, or a single instance. To indicate this, set the `detail` argument to `True` or `False`. The router will configure its URL patterns accordingly. e.g., the `DefaultRouter` will configure detail actions to contain `pk` in their URL patterns. +If you have ad-hoc methods that should be routable, you can mark them as such with the `@action` decorator. Like regular actions, extra actions may be intended for either a single object, or an entire collection. To indicate this, set the `detail` argument to `True` or `False`. The router will configure its URL patterns accordingly. e.g., the `DefaultRouter` will configure detail actions to contain `pk` in their URL patterns. A more complete example of extra actions: @@ -158,7 +158,7 @@ A more complete example of extra actions: @action(detail=False) def recent_users(self, request): - recent_users = User.objects.all().order('-last_login') + recent_users = User.objects.all().order_by('-last_login') page = self.paginate_queryset(recent_users) if page is not None: @@ -174,7 +174,7 @@ The decorator can additionally take extra arguments that will be set for the rou 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: +The `action` decorator will route `GET` requests by default, but may also accept other HTTP methods by setting the `methods` argument. For example: @action(detail=True, methods=['post', 'delete']) def unset_password(self, request, pk=None): @@ -186,7 +186,7 @@ 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. +Extra actions can map additional HTTP methods to separate `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. ```python @action(detail=True, methods=['put'], name='Change Password') @@ -314,5 +314,5 @@ To create a base viewset class that provides `create`, `list` and `retrieve` ope By creating your own base `ViewSet` classes, you can provide common behavior that can be reused in multiple viewsets across your API. -[cite]: http://guides.rubyonrails.org/routing.html +[cite]: https://guides.rubyonrails.org/routing.html [routers]: routers.md diff --git a/docs/community/3.0-announcement.md b/docs/community/3.0-announcement.md index 66a035380..83aec9e60 100644 --- a/docs/community/3.0-announcement.md +++ b/docs/community/3.0-announcement.md @@ -960,6 +960,6 @@ The 3.2 release is planned to introduce an alternative admin-style interface to You can follow development on the GitHub site, where we use [milestones to indicate planning timescales](https://github.com/encode/django-rest-framework/milestones). [kickstarter]: https://www.kickstarter.com/projects/tomchristie/django-rest-framework-3 -[sponsors]: http://www.django-rest-framework.org/topics/kickstarter-announcement/#sponsors +[sponsors]: https://www.django-rest-framework.org/topics/kickstarter-announcement/#sponsors [mixins.py]: https://github.com/encode/django-rest-framework/blob/master/rest_framework/mixins.py [django-localization]: https://docs.djangoproject.com/en/stable/topics/i18n/translation/#localization-how-to-create-language-files diff --git a/docs/community/3.2-announcement.md b/docs/community/3.2-announcement.md index c022231a0..a6db0e54b 100644 --- a/docs/community/3.2-announcement.md +++ b/docs/community/3.2-announcement.md @@ -10,7 +10,7 @@ We've also fixed a huge number of issues, and made numerous cleanups and improve Over the course of the 3.1.x series we've [resolved nearly 600 tickets](https://github.com/encode/django-rest-framework/issues?utf8=%E2%9C%93&q=closed%3A%3E2015-03-05) on our GitHub issue tracker. This means we're currently running at a rate of **closing around 100 issues or pull requests per month**. -None of this would have been possible without the support of our wonderful Kickstarter backers. If you're looking for a job in Django development we'd strongly recommend taking [a look through our sponsors](http://www.django-rest-framework.org/topics/kickstarter-announcement/#sponsors) and finding out who's hiring. +None of this would have been possible without the support of our wonderful Kickstarter backers. If you're looking for a job in Django development we'd strongly recommend taking [a look through our sponsors](https://www.django-rest-framework.org/topics/kickstarter-announcement/#sponsors) and finding out who's hiring. ## AdminRenderer diff --git a/docs/community/3.4-announcement.md b/docs/community/3.4-announcement.md index 73ec3f2a2..44270fd85 100644 --- a/docs/community/3.4-announcement.md +++ b/docs/community/3.4-announcement.md @@ -178,12 +178,12 @@ The full set of itemized release notes [are available here][release-notes]. [sponsors]: https://fund.django-rest-framework.org/topics/funding/#our-sponsors [moss]: mozilla-grant.md [funding]: funding.md -[core-api]: http://www.coreapi.org/ +[core-api]: https://www.coreapi.org/ [command-line-client]: api-clients#command-line-client [client-library]: api-clients#python-client-library -[core-json]: http://www.coreapi.org/specification/encoding/#core-json-encoding +[core-json]: https://www.coreapi.org/specification/encoding/#core-json-encoding [swagger]: https://openapis.org/specification -[hyperschema]: http://json-schema.org/latest/json-schema-hypermedia.html +[hyperschema]: https://json-schema.org/latest/json-schema-hypermedia.html [api-blueprint]: https://apiblueprint.org/ [tut-7]: ../tutorial/7-schemas-and-client-libraries/ [schema-generation]: ../api-guide/schemas/ diff --git a/docs/community/3.9-announcement.md b/docs/community/3.9-announcement.md new file mode 100644 index 000000000..3cd9b1a54 --- /dev/null +++ b/docs/community/3.9-announcement.md @@ -0,0 +1,212 @@ + + +# Django REST framework 3.9 + +The 3.9 release gives access to _extra actions_ in the Browsable API, introduces composable permissions and built-in [OpenAPI][openapi] schema support. (Formerly known as Swagger) + +--- + +## Funding + +If you use REST framework commercially and would like to see this work continue, we strongly encourage you to invest in its continued development by +**[signing up for a paid plan][funding]**. + + + +
+ +*Many thanks to all our [wonderful sponsors][sponsors], and in particular to our premium backers, [Rover](http://jobs.rover.com/), [Sentry](https://getsentry.com/welcome/), [Stream](https://getstream.io/?utm_source=drf&utm_medium=banner&utm_campaign=drf), [Auklet](https://auklet.io/), [Rollbar](https://rollbar.com), [Cadre](https://cadre.com), [Load Impact](https://loadimpact.com/?utm_campaign=Sponsorship%20links&utm_source=drf&utm_medium=drf), and [Kloudless](https://hubs.ly/H0f30Lf0).* + +--- + +## Built-in OpenAPI schema support + +REST framework now has a first-pass at directly including OpenAPI schema support. (Formerly known as Swagger) + +Specifically: + +* There are now `OpenAPIRenderer`, and `JSONOpenAPIRenderer` classes that deal with encoding `coreapi.Document` instances into OpenAPI YAML or OpenAPI JSON. +* The `get_schema_view(...)` method now defaults to OpenAPI YAML, with CoreJSON as a secondary +option if it is selected via HTTP content negotiation. +* There is a new management command `generateschema`, which you can use to dump +the schema into your repository. + +Here's an example of adding an OpenAPI schema to the URL conf: + +```python +from rest_framework.schemas import get_schema_view +from rest_framework.renderers import JSONOpenAPIRenderer + +schema_view = get_schema_view( + title='Server Monitoring API', + url='https://www.example.org/api/', + renderer_classes=[JSONOpenAPIRenderer] +) + +urlpatterns = [ + url('^schema.json$', schema_view), + ... +] +``` + +And here's how you can use the `generateschema` management command: + +```shell +$ python manage.py generateschema --format openapi > schema.yml +``` + +There's lots of different tooling that you can use for working with OpenAPI +schemas. One option that we're working on is the [API Star](https://docs.apistar.com/) +command line tool. + +You can use `apistar` to validate your API schema: + +```shell +$ apistar validate --path schema.json --format openapi +✓ Valid OpenAPI schema. +``` + +Or to build API documentation: + +```shell +$ apistar docs --path schema.json --format openapi +✓ Documentation built at "build/index.html". +``` + +API Star also includes a [dynamic client library](https://docs.apistar.com/client-library/) +that uses an API schema to automatically provide a client library interface for making requests. + +## Composable permission classes + +You can now compose permission classes using the and/or operators, `&` and `|`. + +For example... + +```python +permission_classes = [IsAuthenticated & (ReadOnly | IsAdmin)] +``` + +If you're using custom permission classes then make sure that you are subclassing +from `BasePermission` in order to enable this support. + +## ViewSet _Extra Actions_ available in the Browsable API + +Following the introduction of the `action` decorator in v3.8, _extra actions_ defined on a ViewSet are now available +from the Browsable API. + +![Extra Actions displayed in the Browsable API](https://user-images.githubusercontent.com/2370209/32976956-1ca9ab7e-cbf1-11e7-981a-a20cb1e83d63.png) + +When defined, a dropdown of "Extra Actions", appropriately filtered to detail/non-detail actions, is displayed. + +--- + +## Supported Versions + +REST framework 3.9 supports Django versions 1.11, 2.0, and 2.1. + +--- + +## Deprecations + +### `DjangoObjectPermissionsFilter` moved to third-party package. + +The `DjangoObjectPermissionsFilter` class is pending deprecation, will be deprecated in 3.10 and removed entirely in 3.11. + +It has been moved to the third-party [`djangorestframework-guardian`](https://github.com/rpkilby/django-rest-framework-guardian) +package. Please use this instead. + +### Router argument/method renamed to use `basename` for consistency. + +* The `Router.register` `base_name` argument has been renamed in favor of `basename`. +* The `Router.get_default_base_name` method has been renamed in favor of `Router.get_default_basename`. [#5990][gh5990] + +See [#5990][gh5990]. + +[gh5990]: https://github.com/encode/django-rest-framework/pull/5990 + +`base_name` and `get_default_base_name()` are pending deprecation. They will be deprecated in 3.10 and removed entirely in 3.11. + +### `action` decorator replaces `list_route` and `detail_route` + +Both `list_route` and `detail_route` are now deprecated in favour of the single `action` decorator. +They will be removed entirely in 3.10. + +The `action` decorator takes a boolean `detail` argument. + +* Replace `detail_route` uses with `@action(detail=True)`. +* Replace `list_route` uses with `@action(detail=False)`. + +### `exclude_from_schema` + +Both `APIView.exclude_from_schema` and the `exclude_from_schema` argument to the `@api_view` have now been removed. + +For `APIView` you should instead set a `schema = None` attribute on the view class. + +For function based views the `@schema` decorator can be used to exclude the view from the schema, by using `@schema(None)`. + +--- + +## Minor fixes and improvements + +There are a large number of minor fixes and improvements in this release. See the [release notes](release-notes.md) page for a complete listing. + + +## What's next + +We're planning to iteratively working towards OpenAPI becoming the standard schema +representation. This will mean that the `coreapi` dependency will gradually become +removed, and we'll instead generate the schema directly, rather than building +a CoreAPI `Document` object. + +OpenAPI has clearly become the standard for specifying Web APIs, so there's not +much value any more in our schema-agnostic document model. Making this change +will mean that we'll more easily be able to take advantage of the full set of +OpenAPI functionality. + +This will also make a wider range of tooling available. + +We'll focus on continuing to develop the [API Star](https://docs.apistar.com/) +library and client tool into a recommended option for generating API docs, +validating API schemas, and providing a dynamic client library. + +There's also a huge amount of ongoing work on maturing the ASGI landscape, +with the possibility that some of this work will eventually [feed back into +Django](https://www.aeracode.org/2018/06/04/django-async-roadmap/). + +There will be further work on the [Uvicorn](https://www.uvicorn.org/) +webserver, as well as lots of functionality planned for the [Starlette](https://www.starlette.io/) +web framework, which is building a foundational set of tooling for working with +ASGI. + + +[funding]: funding.md +[gh5886]: https://github.com/encode/django-rest-framework/issues/5886 +[gh5705]: https://github.com/encode/django-rest-framework/issues/5705 +[openapi]: https://www.openapis.org/ +[sponsors]: https://fund.django-rest-framework.org/topics/funding/#our-sponsors diff --git a/docs/community/funding.md b/docs/community/funding.md index 0faf2164b..8f0e02515 100644 --- a/docs/community/funding.md +++ b/docs/community/funding.md @@ -123,10 +123,10 @@ REST framework continues to be open-source and permissively licensed, but we fir ## What funding has enabled so far -* The [3.4](http://www.django-rest-framework.org/topics/3.4-announcement/) and [3.5](http://www.django-rest-framework.org/topics/3.5-announcement/) releases, including schema generation for both Swagger and RAML, a Python client library, a Command Line client, and addressing of a large number of outstanding issues. -* The [3.6](http://www.django-rest-framework.org/topics/3.6-announcement/) release, including JavaScript client library, and API documentation, complete with auto-generated code samples. -* The [3.7 release](http://www.django-rest-framework.org/topics/3.7-announcement/), made possible due to our collaborative funding model, focuses on improvements to schema generation and the interactive API documentation. -* The recent [3.8 release](http://www.django-rest-framework.org/topics/3.8-announcement/). +* The [3.4](https://www.django-rest-framework.org/topics/3.4-announcement/) and [3.5](https://www.django-rest-framework.org/topics/3.5-announcement/) releases, including schema generation for both Swagger and RAML, a Python client library, a Command Line client, and addressing of a large number of outstanding issues. +* The [3.6](https://www.django-rest-framework.org/topics/3.6-announcement/) release, including JavaScript client library, and API documentation, complete with auto-generated code samples. +* The [3.7 release](https://www.django-rest-framework.org/topics/3.7-announcement/), made possible due to our collaborative funding model, focuses on improvements to schema generation and the interactive API documentation. +* The recent [3.8 release](https://www.django-rest-framework.org/topics/3.8-announcement/). * Tom Christie, the creator of Django REST framework, working on the project full-time. * Around 80-90 issues and pull requests closed per month since Tom Christie started working on the project full-time. * A community & operations manager position part-time for 4 months, helping mature the business and grow sponsorship. @@ -341,7 +341,7 @@ For further enquires please contact diff --git a/docs/community/kickstarter-announcement.md b/docs/community/kickstarter-announcement.md index e2a283e29..0e5d95b2c 100644 --- a/docs/community/kickstarter-announcement.md +++ b/docs/community/kickstarter-announcement.md @@ -78,7 +78,7 @@ Our gold sponsors include companies large and small. Many thanks for their signi
  • Mirus Research
  • Hipo
  • Byte
  • -
  • Lightning Kite
  • +
  • Lightning Kite
  • Opbeat
  • Koordinates
  • Pulsecode Inc.
  • @@ -116,7 +116,7 @@ The serious financial contribution that our silver sponsors have made is very mu
  • Garfo
  • Shippo
  • Gizmag
  • -
  • Tivix
  • +
  • Tivix
  • Safari
  • Bright Loop
  • ABA Systems
  • @@ -131,7 +131,7 @@ The serious financial contribution that our silver sponsors have made is very mu
  • Fluxility
  • Teonite
  • TrackMaven
  • -
  • Phurba
  • +
  • Phurba
  • Nephila
  • Aditium
  • OpenEye Scientific Software
  • diff --git a/docs/community/mozilla-grant.md b/docs/community/mozilla-grant.md index 4d9b1d438..5248f5cc0 100644 --- a/docs/community/mozilla-grant.md +++ b/docs/community/mozilla-grant.md @@ -4,7 +4,7 @@ We have recently been [awarded a Mozilla grant](https://blog.mozilla.org/blog/20 Additionally, we will be building on the realtime support that Django Channels provides, supporting and documenting how to build realtime APIs with REST framework. Again, this will include supporting work in the associated client libraries, making it easier to build richly interactive applications. -The [Core API](http://www.coreapi.org) project will provide the foundations for our client library support, and will allow us to support interaction using a wide range of schemas and hypermedia formats. It's worth noting that these client libraries won't be tightly coupled to solely REST framework APIs either, and will be able to interact with *any* API that exposes a supported schema or hypermedia format. +The [Core API](https://www.coreapi.org/) project will provide the foundations for our client library support, and will allow us to support interaction using a wide range of schemas and hypermedia formats. It's worth noting that these client libraries won't be tightly coupled to solely REST framework APIs either, and will be able to interact with *any* API that exposes a supported schema or hypermedia format. Specifically, the work includes: @@ -34,7 +34,7 @@ In order to ensure that I can be fully focused on trying to secure a sustainable & well-funded open source business I will be leaving my current role at [DabApps](https://www.dabapps.com/) at the end of May 2016. -I have formed a UK limited company, [Encode](http://www.encode.io), which will +I have formed a UK limited company, [Encode](https://www.encode.io/), which will act as the business entity behind REST framework. I will be issuing monthly reports from Encode on progress both towards the Mozilla grant, and for development time funded via the [REST framework paid plans](funding.md). diff --git a/docs/community/project-management.md b/docs/community/project-management.md index c7f064e13..5d7dab561 100644 --- a/docs/community/project-management.md +++ b/docs/community/project-management.md @@ -39,7 +39,7 @@ The following template should be used for the description of the issue, and serv This issue is for determining the maintenance team for the *** period. - Please see the [Project management](http://www.django-rest-framework.org/topics/project-management/) section of our documentation for more details. + Please see the [Project management](https://www.django-rest-framework.org/topics/project-management/) section of our documentation for more details. --- @@ -59,7 +59,7 @@ The following template should be used for the description of the issue, and serv If you wish to be considered for this or a future date, please comment against this or subsequent issues. - To modify this process for future maintenance cycles make a pull request to the [project management](http://www.django-rest-framework.org/topics/project-management/) documentation. + To modify this process for future maintenance cycles make a pull request to the [project management](https://www.django-rest-framework.org/topics/project-management/) documentation. #### Responsibilities of team members @@ -99,7 +99,7 @@ The following template should be used for the description of the issue, and serv During development cycle: - - [ ] Upload the new content to be translated to [transifex](http://www.django-rest-framework.org/topics/project-management/#translations). + - [ ] Upload the new content to be translated to [transifex](https://www.django-rest-framework.org/topics/project-management/#translations). Checklist: @@ -110,7 +110,7 @@ The following template should be used for the description of the issue, and serv - [ ] `setup.py` Python & Django version trove classifiers - [ ] `README` Python & Django versions - [ ] `docs` Python & Django versions - - [ ] Update the translations from [transifex](http://www.django-rest-framework.org/topics/project-management/#translations). + - [ ] Update the translations from [transifex](https://www.django-rest-framework.org/topics/project-management/#translations). - [ ] Ensure the pull request increments the version to `*.*.*` in [`restframework/__init__.py`](https://github.com/encode/django-rest-framework/blob/master/rest_framework/__init__.py). - [ ] Confirm with @tomchristie that release is finalized and ready to go. - [ ] Ensure that release date is included in pull request. @@ -122,7 +122,7 @@ The following template should be used for the description of the issue, and serv - [ ] Make a release announcement on twitter. - [ ] Close the milestone on GitHub. - To modify this process for future releases make a pull request to the [project management](http://www.django-rest-framework.org/topics/project-management/) documentation. + To modify this process for future releases make a pull request to the [project management](https://www.django-rest-framework.org/topics/project-management/) documentation. When pushing the release to PyPI ensure that your environment has been installed from our development `requirement.txt`, so that documentation and PyPI installs are consistently being built against a pinned set of packages. @@ -152,7 +152,7 @@ When any user visible strings are changed, they should be uploaded to Transifex # 1. Update the source django.po file, which is the US English version. cd rest_framework - django-admin.py makemessages -l en_US + django-admin makemessages -l en_US # 2. Push the source django.po file to Transifex. cd .. tx push -s @@ -173,7 +173,7 @@ When a translator has finished translating their work needs to be downloaded fro tx pull -a --minimum-perc 10 cd rest_framework # 4. Compile the binary .mo files for all supported languages. - django-admin.py compilemessages + django-admin compilemessages --- diff --git a/docs/community/release-notes.md b/docs/community/release-notes.md index e9f8d5abc..55e63daff 100644 --- a/docs/community/release-notes.md +++ b/docs/community/release-notes.md @@ -42,10 +42,52 @@ You can determine your currently installed version using `pip show`: ### 3.9.0 -**Date**: Unreleased +**Date**: [18th October 2018][3.9.0-milestone] +* Improvements to ViewSet extra actions [#5605][gh5605] +* Fix `action` support for ViewSet suffixes [#6081][gh6081] +* Allow `action` docs sections [#6060][gh6060] * Deprecate the `Router.register` `base_name` argument in favor of `basename`. [#5990][gh5990] * Deprecate the `Router.get_default_base_name` method in favor of `Router.get_default_basename`. [#5990][gh5990] +* Change `CharField` to disallow null bytes. [#6073][gh6073] + To revert to the old behavior, subclass `CharField` and remove `ProhibitNullCharactersValidator` from the validators. + ```python + class NullableCharField(serializers.CharField): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.validators = [v for v in self.validators if not isinstance(v, ProhibitNullCharactersValidator)] + ``` +* Add `OpenAPIRenderer` and `generate_schema` management command. [#6229][gh6229] +* Add OpenAPIRenderer by default, and add schema docs. [#6233][gh6233] +* Allow permissions to be composed [#5753][gh5753] +* Allow nullable BooleanField in Django 2.1 [#6183][gh6183] +* Add testing of Python 3.7 support [#6141][gh6141] +* Test using Django 2.1 final release. [#6109][gh6109] +* Added djangorestframework-datatables to third-party packages [#5931][gh5931] +* Change ISO 8601 date format to exclude year/month [#5936][gh5936] +* Update all pypi.python.org URLs to pypi.org [#5942][gh5942] +* Ensure that html forms (multipart form data) respect optional fields [#5927][gh5927] +* Allow hashing of ErrorDetail. [#5932][gh5932] +* Correct schema parsing for JSONField [#5878][gh5878] +* Render descriptions (from help_text) using safe [#5869][gh5869] +* Removed input value from deault_error_message [#5881][gh5881] +* Added min_value/max_value support in DurationField [#5643][gh5643] +* Fixed instance being overwritten in pk-only optimization try/except block [#5747][gh5747] +* Fixed AttributeError from items filter when value is None [#5981][gh5981] +* Fixed Javascript `e.indexOf` is not a function error [#5982][gh5982] +* Fix schemas for extra actions [#5992][gh5992] +* Improved get_error_detail to use error_dict/error_list [#5785][gh5785] +* Imprvied URLs in Admin renderer [#5988][gh5988] +* Add "Community" section to docs, minor cleanup [#5993][gh5993] +* Moved guardian imports out of compat [#6054][gh6054] +* Deprecate the `DjangoObjectPermissionsFilter` class, moved to the `djangorestframework-guardian` package. [#6075][gh6075] +* Drop Django 1.10 support [#5657][gh5657] +* Only catch TypeError/ValueError for object lookups [#6028][gh6028] +* Handle models without .objects manager in ModelSerializer. [#6111][gh6111] +* Improve ModelSerializer.create() error message. [#6112][gh6112] +* Fix CSRF cookie check failure when using session auth with django 1.11.6+ [#6113][gh6113] +* Updated JWT docs. [#6138][gh6138] +* Fix autoescape not getting passed to urlize_quoted_links filter [#6191][gh6191] ## 3.8.x series @@ -1092,6 +1134,7 @@ For older release notes, [please see the version 2.x documentation][old-release- [3.8.0-milestone]: https://github.com/encode/django-rest-framework/milestone/61?closed=1 [3.8.1-milestone]: https://github.com/encode/django-rest-framework/milestone/67?closed=1 [3.8.2-milestone]: https://github.com/encode/django-rest-framework/milestone/68?closed=1 +[3.9.0-milestone]: https://github.com/encode/django-rest-framework/milestone/66?closed=1 [gh2013]: https://github.com/encode/django-rest-framework/issues/2013 @@ -1973,4 +2016,39 @@ For older release notes, [please see the version 2.x documentation][old-release- [gh5920]: https://github.com/encode/django-rest-framework/issues/5920 +[gh6109]: https://github.com/encode/django-rest-framework/issues/6109 +[gh6141]: https://github.com/encode/django-rest-framework/issues/6141 +[gh6113]: https://github.com/encode/django-rest-framework/issues/6113 +[gh6112]: https://github.com/encode/django-rest-framework/issues/6112 +[gh6111]: https://github.com/encode/django-rest-framework/issues/6111 +[gh6028]: https://github.com/encode/django-rest-framework/issues/6028 +[gh5657]: https://github.com/encode/django-rest-framework/issues/5657 +[gh6054]: https://github.com/encode/django-rest-framework/issues/6054 +[gh5993]: https://github.com/encode/django-rest-framework/issues/5993 [gh5990]: https://github.com/encode/django-rest-framework/issues/5990 +[gh5988]: https://github.com/encode/django-rest-framework/issues/5988 +[gh5785]: https://github.com/encode/django-rest-framework/issues/5785 +[gh5992]: https://github.com/encode/django-rest-framework/issues/5992 +[gh5605]: https://github.com/encode/django-rest-framework/issues/5605 +[gh5982]: https://github.com/encode/django-rest-framework/issues/5982 +[gh5981]: https://github.com/encode/django-rest-framework/issues/5981 +[gh5747]: https://github.com/encode/django-rest-framework/issues/5747 +[gh5643]: https://github.com/encode/django-rest-framework/issues/5643 +[gh5881]: https://github.com/encode/django-rest-framework/issues/5881 +[gh5869]: https://github.com/encode/django-rest-framework/issues/5869 +[gh5878]: https://github.com/encode/django-rest-framework/issues/5878 +[gh5932]: https://github.com/encode/django-rest-framework/issues/5932 +[gh5927]: https://github.com/encode/django-rest-framework/issues/5927 +[gh5942]: https://github.com/encode/django-rest-framework/issues/5942 +[gh5936]: https://github.com/encode/django-rest-framework/issues/5936 +[gh5931]: https://github.com/encode/django-rest-framework/issues/5931 +[gh6183]: https://github.com/encode/django-rest-framework/issues/6183 +[gh6075]: https://github.com/encode/django-rest-framework/issues/6075 +[gh6138]: https://github.com/encode/django-rest-framework/issues/6138 +[gh6081]: https://github.com/encode/django-rest-framework/issues/6081 +[gh6073]: https://github.com/encode/django-rest-framework/issues/6073 +[gh6191]: https://github.com/encode/django-rest-framework/issues/6191 +[gh6060]: https://github.com/encode/django-rest-framework/issues/6060 +[gh6233]: https://github.com/encode/django-rest-framework/issues/6233 +[gh5753]: https://github.com/encode/django-rest-framework/issues/5753 +[gh6229]: https://github.com/encode/django-rest-framework/issues/6229 diff --git a/docs/community/tutorials-and-resources.md b/docs/community/tutorials-and-resources.md index 8c30bbeaa..a03d63a3c 100644 --- a/docs/community/tutorials-and-resources.md +++ b/docs/community/tutorials-and-resources.md @@ -85,8 +85,8 @@ Want your Django REST Framework talk/tutorial/article to be added to our website [beginners-guide-to-the-django-rest-framework]: https://code.tutsplus.com/tutorials/beginners-guide-to-the-django-rest-framework--cms-19786 -[getting-started-with-django-rest-framework-and-angularjs]: http://blog.kevinastone.com/getting-started-with-django-rest-framework-and-angularjs.html -[end-to-end-web-app-with-django-rest-framework-angularjs]: http://mourafiq.com/2013/07/01/end-to-end-web-app-with-django-angular-1.html +[getting-started-with-django-rest-framework-and-angularjs]: https://blog.kevinastone.com/getting-started-with-django-rest-framework-and-angularjs.html +[end-to-end-web-app-with-django-rest-framework-angularjs]: https://mourafiq.com/2013/07/01/end-to-end-web-app-with-django-angular-1.html [start-your-api-django-rest-framework-part-1]: https://godjango.com/41-start-your-api-django-rest-framework-part-1/ [permissions-authentication-django-rest-framework-part-2]: https://godjango.com/43-permissions-authentication-django-rest-framework-part-2/ [viewsets-and-routers-django-rest-framework-part-3]: https://godjango.com/45-viewsets-and-routers-django-rest-framework-part-3/ diff --git a/docs/img/drf-openapi.png b/docs/img/drf-openapi.png deleted file mode 100644 index 7a37e19d6..000000000 Binary files a/docs/img/drf-openapi.png and /dev/null differ diff --git a/docs/img/premium/auklet-readme.png b/docs/img/premium/auklet-readme.png new file mode 100644 index 000000000..f55f7a70e Binary files /dev/null and b/docs/img/premium/auklet-readme.png differ diff --git a/docs/img/premium/kloudless-readme.png b/docs/img/premium/kloudless-readme.png new file mode 100644 index 000000000..63fabec1b Binary files /dev/null and b/docs/img/premium/kloudless-readme.png differ diff --git a/docs/img/premium/load-impact-readme.png b/docs/img/premium/load-impact-readme.png new file mode 100644 index 000000000..c46d36ada Binary files /dev/null and b/docs/img/premium/load-impact-readme.png differ diff --git a/docs/index.md b/docs/index.md index f709502d7..c250aa0af 100644 --- a/docs/index.md +++ b/docs/index.md @@ -69,13 +69,15 @@ continued development by **[signing up for a paid plan][funding]**.
  • Rover.com
  • Sentry
  • Stream
  • -
  • Machinalis
  • +
  • Auklet
  • Rollbar
  • Cadre
  • +
  • Load Impact
  • +
  • Kloudless
  • -*Many thanks to all our [wonderful sponsors][sponsors], and in particular to our premium backers, [Rover](http://jobs.rover.com/), [Sentry](https://getsentry.com/welcome/), [Stream](https://getstream.io/?utm_source=drf&utm_medium=banner&utm_campaign=drf), [Machinalis](https://hello.machinalis.co.uk/), [Rollbar](https://rollbar.com), and [Cadre](https://cadre.com).* +*Many thanks to all our [wonderful sponsors][sponsors], and in particular to our premium backers, [Rover](http://jobs.rover.com/), [Sentry](https://getsentry.com/welcome/), [Stream](https://getstream.io/?utm_source=drf&utm_medium=banner&utm_campaign=drf), [Auklet](https://auklet.io/), [Rollbar](https://rollbar.com), [Cadre](https://cadre.com), [Load Impact](https://loadimpact.com/?utm_campaign=Sponsorship%20links&utm_source=drf&utm_medium=drf), and [Kloudless](https://hubs.ly/H0f30Lf0).* --- @@ -83,8 +85,8 @@ continued development by **[signing up for a paid plan][funding]**. REST framework requires the following: -* Python (2.7, 3.4, 3.5, 3.6) -* Django (1.11, 2.0) +* Python (2.7, 3.4, 3.5, 3.6, 3.7) +* Django (1.11, 2.0, 2.1) The following packages are optional: @@ -200,17 +202,22 @@ Send a description of the issue via email to [rest-framework-security@googlegrou ## License -Copyright (c) 2011-2017, Tom Christie +Copyright © 2011-present, [Encode OSS Ltd](https://www.encode.io/). All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: -Redistributions of source code must retain the above copyright notice, this -list of conditions and the following disclaimer. -Redistributions in binary form must reproduce the above copyright notice, this -list of conditions and the following disclaimer in the documentation and/or -other materials provided with the distribution. +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED diff --git a/docs/topics/api-clients.md b/docs/topics/api-clients.md index ec0b4272c..3fd560634 100644 --- a/docs/topics/api-clients.md +++ b/docs/topics/api-clients.md @@ -521,7 +521,7 @@ You'll either want to include the API schema in your codebase directly, by copyi }) [heroku-api]: https://devcenter.heroku.com/categories/platform-api -[heroku-example]: http://www.coreapi.org/tools-and-resources/example-services/#heroku-json-hyper-schema -[core-api]: http://www.coreapi.org/ +[heroku-example]: https://www.coreapi.org/tools-and-resources/example-services/#heroku-json-hyper-schema +[core-api]: https://www.coreapi.org/ [schema-generation]: ../api-guide/schemas.md [transport-adaptors]: http://docs.python-requests.org/en/master/user/advanced/#transport-adapters diff --git a/docs/topics/browser-enhancements.md b/docs/topics/browser-enhancements.md index 32eab43a8..0e79a66e1 100644 --- a/docs/topics/browser-enhancements.md +++ b/docs/topics/browser-enhancements.md @@ -82,6 +82,6 @@ as well as how to support content types other than form-encoded data. [cite]: https://www.amazon.com/RESTful-Web-Services-Leonard-Richardson/dp/0596529260 [ajax-form]: https://github.com/encode/ajax-form -[rails]: http://guides.rubyonrails.org/form_helpers.html#how-do-forms-with-put-or-delete-methods-work +[rails]: https://guides.rubyonrails.org/form_helpers.html#how-do-forms-with-put-or-delete-methods-work [html5]: https://www.w3.org/TR/html5-diff/#changes-2010-06-24 [put_delete]: http://amundsen.com/examples/put-delete-forms/ diff --git a/docs/topics/documenting-your-api.md b/docs/topics/documenting-your-api.md index d57f9d6e4..7eab08ecf 100644 --- a/docs/topics/documenting-your-api.md +++ b/docs/topics/documenting-your-api.md @@ -16,11 +16,11 @@ The built-in API documentation includes: ### Installation -The `coreapi` library is required as a dependancy for the API docs. Make sure +The `coreapi` library is required as a dependency for the API docs. Make sure to install the latest version. The `pygments` and `markdown` libraries are optional but recommended. -To install the API documentation, you'll need to include it in your projects URLconf: +To install the API documentation, you'll need to include it in your project's URLconf: from rest_framework.documentation import include_docs_urls @@ -39,7 +39,7 @@ This will include two different views: **Note**: By default `include_docs_urls` configures the underlying `SchemaView` to generate _public_ schemas. This means that views will not be instantiated with a `request` instance. i.e. Inside the view `self.request` will be `None`. -To be compatible with this behaviour methods (such as `get_serializer` or `get_serializer_class` etc.) which inspect `self.request` or, particularly, `self.request.user` may need to be adjusted to handle this case. +To be compatible with this behaviour, methods (such as `get_serializer` or `get_serializer_class` etc.) which inspect `self.request` or, particularly, `self.request.user` may need to be adjusted to handle this case. You may ensure views are given a `request` instance by calling `include_docs_urls` with `public=False`: @@ -90,6 +90,28 @@ When using viewsets, you should use the relevant action names as delimiters. Create a new user instance. """ +Custom actions on viewsets can also be documented in a similar way using the method names +as delimiters or by attaching the documentation to action mapping methods. + + class UserViewSet(viewsets.ModelViewset): + ... + + @action(detail=False, methods=['get', 'post']) + def some_action(self, request, *args, **kwargs): + """ + get: + A description of the get method on the custom action. + + post: + A description of the post method on the custom action. + """ + + @some_action.mapping.put + def put_some_action(): + """ + A description of the put method on the custom action. + """ + ### `documentation` API Reference @@ -171,22 +193,6 @@ This also translates into a very useful interactive documentation viewer in the ![Screenshot - drf-yasg][image-drf-yasg] - -#### DRF OpenAPI - -[DRF OpenAPI][drf-openapi] bridges the gap between OpenAPI specification and tool chain with the schema exposed -out-of-the-box by Django Rest Framework. Its goals are: - - * To be dropped into any existing DRF project without any code change necessary. - * Provide clear disctinction between request schema and response schema. - * Provide a versioning mechanism for each schema. Support defining schema by version range syntax, e.g. >1.0, <=2.0 - * Support multiple response codes, not just 200 - * All this information should be bound to view methods, not view classes. - -It also tries to stay current with the maturing schema generation mechanism provided by DRF. - -![Screenshot - DRF OpenAPI][image-drf-openapi] - --- #### DRF Docs @@ -313,11 +319,9 @@ In this approach, rather than documenting the available API endpoints up front, To implement a hypermedia API you'll need to decide on an appropriate media type for the API, and implement a custom renderer and parser for that media type. The [REST, Hypermedia & HATEOAS][hypermedia-docs] section of the documentation includes pointers to background reading, as well as links to various hypermedia formats. -[cite]: http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven +[cite]: https://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven [drf-yasg]: https://github.com/axnsan12/drf-yasg/ [image-drf-yasg]: ../img/drf-yasg.png -[drf-openapi]: https://github.com/limdauto/drf_openapi/ -[image-drf-openapi]: ../img/drf-openapi.png [drfdocs-repo]: https://github.com/ekonstantinidis/django-rest-framework-docs [drfdocs-website]: https://www.drfdocs.com/ [drfdocs-demo]: http://demo.drfdocs.com/ diff --git a/docs/topics/html-and-forms.md b/docs/topics/html-and-forms.md index 0b4afca12..18774926b 100644 --- a/docs/topics/html-and-forms.md +++ b/docs/topics/html-and-forms.md @@ -4,7 +4,7 @@ REST framework is suitable for returning both API style responses, and regular H ## Rendering HTML -In order to return HTML responses you'll need to either `TemplateHTMLRenderer`, or `StaticHTMLRenderer`. +In order to return HTML responses you'll need to use either `TemplateHTMLRenderer`, or `StaticHTMLRenderer`. The `TemplateHTMLRenderer` class expects the response to contain a dictionary of context data, and renders an HTML page based on a template that must be specified either in the view or on the response. diff --git a/docs/topics/internationalization.md b/docs/topics/internationalization.md index ed8b85836..7cfc6e247 100644 --- a/docs/topics/internationalization.md +++ b/docs/topics/internationalization.md @@ -43,7 +43,7 @@ REST framework includes these built-in translations both for standard exception Note that the translations only apply to the error strings themselves. The format of error messages, and the keys of field names will remain the same. An example `400 Bad Request` response body might look like this: - {"detail": {"username": ["Esse campo deve ser unico."]}} + {"detail": {"username": ["Esse campo deve ser único."]}} If you want to use different string for parts of the response such as `detail` and `non_field_errors` then you can modify this behavior by using a [custom exception handler][custom-exception-handler]. diff --git a/docs/topics/rest-hypermedia-hateoas.md b/docs/topics/rest-hypermedia-hateoas.md index aa889f62b..d48319a26 100644 --- a/docs/topics/rest-hypermedia-hateoas.md +++ b/docs/topics/rest-hypermedia-hateoas.md @@ -36,7 +36,7 @@ What REST framework doesn't do is give you machine readable hypermedia formats s [cite]: https://vimeo.com/channels/restfest/page:2 [dissertation]: https://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm -[hypertext-driven]: http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven +[hypertext-driven]: https://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven [restful-web-apis]: http://restfulwebapis.org/ [building-hypermedia-apis]: https://www.amazon.com/Building-Hypermedia-APIs-HTML5-Node/dp/1449306578 [designing-hypermedia-apis]: http://designinghypermediaapis.com/ diff --git a/docs/topics/writable-nested-serializers.md b/docs/topics/writable-nested-serializers.md index a39feb18c..9ba719f4e 100644 --- a/docs/topics/writable-nested-serializers.md +++ b/docs/topics/writable-nested-serializers.md @@ -27,7 +27,7 @@ Nested data structures are easy enough to work with if they're read-only - simpl Some example output from our serializer. { - 'title': 'Leaving party preperations', + 'title': 'Leaving party preparations', 'items': [ {'text': 'Compile playlist', 'is_completed': True}, {'text': 'Send invites', 'is_completed': False}, diff --git a/docs/tutorial/1-serialization.md b/docs/tutorial/1-serialization.md index aa94eeb0e..387f99eda 100644 --- a/docs/tutorial/1-serialization.md +++ b/docs/tutorial/1-serialization.md @@ -33,7 +33,7 @@ Okay, we're ready to get coding. To get started, let's create a new project to work with. cd ~ - django-admin.py startproject tutorial + django-admin startproject tutorial cd tutorial Once that's done we can create an app that we'll use to create a simple Web API. @@ -154,9 +154,9 @@ At this point we've translated the model instance into Python native datatypes. Deserialization is similar. First we parse a stream into Python native datatypes... - from django.utils.six import BytesIO + import io - stream = BytesIO(content) + stream = io.BytesIO(content) data = JSONParser().parse(stream) ...then we restore those native datatypes into a fully populated object instance. diff --git a/docs/tutorial/5-relationships-and-hyperlinked-apis.md b/docs/tutorial/5-relationships-and-hyperlinked-apis.md index ae24ffeb8..0177afce1 100644 --- a/docs/tutorial/5-relationships-and-hyperlinked-apis.md +++ b/docs/tutorial/5-relationships-and-hyperlinked-apis.md @@ -106,7 +106,7 @@ If we're going to have a hyperlinked API, we need to make sure we name our URL p After adding all those names into our URLconf, our final `snippets/urls.py` file should look like this: - from django.conf.urls import url, include + from django.urls import path from rest_framework.urlpatterns import format_suffix_patterns from snippets import views diff --git a/docs/tutorial/7-schemas-and-client-libraries.md b/docs/tutorial/7-schemas-and-client-libraries.md index f8060ac29..412759834 100644 --- a/docs/tutorial/7-schemas-and-client-libraries.md +++ b/docs/tutorial/7-schemas-and-client-libraries.md @@ -89,7 +89,7 @@ Now check that it is available on the command line... Command line client for interacting with CoreAPI services. - Visit http://www.coreapi.org for more information. + Visit https://www.coreapi.org/ for more information. Options: --version Display the package version number. @@ -220,8 +220,8 @@ We've reached the end of our tutorial. If you want to get more involved in the **Now go build awesome things.** -[coreapi]: http://www.coreapi.org -[corejson]: http://www.coreapi.org/specification/encoding/#core-json-encoding +[coreapi]: https://www.coreapi.org/ +[corejson]: https://www.coreapi.org/specification/encoding/#core-json-encoding [openapi]: https://openapis.org/ [repo]: https://github.com/encode/rest-framework-tutorial [sandbox]: https://restframework.herokuapp.com/ diff --git a/docs/tutorial/quickstart.md b/docs/tutorial/quickstart.md index 466baeebc..108e5742a 100644 --- a/docs/tutorial/quickstart.md +++ b/docs/tutorial/quickstart.md @@ -19,9 +19,9 @@ Create a new Django project named `tutorial`, then start a new app called `quick pip install djangorestframework # Set up a new project with a single application - django-admin.py startproject tutorial . # Note the trailing '.' character + django-admin startproject tutorial . # Note the trailing '.' character cd tutorial - django-admin.py startapp quickstart + django-admin startapp quickstart cd .. The project layout should look like: @@ -56,7 +56,7 @@ We'll also create an initial user named `admin` with a password of `password123` python manage.py createsuperuser --email admin@example.com --username admin -Once you've set up a database and initial user created and ready to go, open up the app's directory and we'll get coding... +Once you've set up a database and the initial user is created and ready to go, open up the app's directory and we'll get coding... ## Serializers diff --git a/docs_theme/404.html b/docs_theme/404.html index 078b9f5ae..a89c0a418 100644 --- a/docs_theme/404.html +++ b/docs_theme/404.html @@ -4,6 +4,6 @@

    404

    Page not found

    -

    Try the homepage, or search the documentation.

    +

    Try the homepage, or search the documentation.

    {% endblock %} diff --git a/docs_theme/css/bootstrap-responsive.css b/docs_theme/css/bootstrap-responsive.css index a8caf451d..ec0b51947 100755 --- a/docs_theme/css/bootstrap-responsive.css +++ b/docs_theme/css/bootstrap-responsive.css @@ -3,7 +3,7 @@ * * Copyright 2012 Twitter, Inc * Licensed under the Apache License v2.0 - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Designed and built with all the love in the world @twitter by @mdo and @fat. */ diff --git a/docs_theme/css/bootstrap.css b/docs_theme/css/bootstrap.css index 53df68595..a48bbbecf 100755 --- a/docs_theme/css/bootstrap.css +++ b/docs_theme/css/bootstrap.css @@ -3,7 +3,7 @@ * * Copyright 2012 Twitter, Inc * Licensed under the Apache License v2.0 - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Designed and built with all the love in the world @twitter by @mdo and @fat. */ diff --git a/docs_theme/nav.html b/docs_theme/nav.html index 914d80a27..f093178d3 100644 --- a/docs_theme/nav.html +++ b/docs_theme/nav.html @@ -14,7 +14,7 @@ - Django REST framework + Django REST framework