You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+7-42Lines changed: 7 additions & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,9 @@ Full documentation for the project is available at [http://www.django-rest-frame
9
9
10
10
---
11
11
12
-
**Note**: We have now released Django REST framework 3.0. For older codebases you may want to refer to the version 2.4.4 [source code](https://github.com/tomchristie/django-rest-framework/tree/version-2.4.x), and [documentation](http://tomchristie.github.io/rest-framework-2-docs/).
12
+
**Note**: We have now released Django REST framework 3.1. For older codebases you may want to refer to the version 2.4.4 [source code](https://github.com/tomchristie/django-rest-framework/tree/version-2.4.x), and [documentation](http://tomchristie.github.io/rest-framework-2-docs/).
13
+
14
+
For more details see the [3.1 release notes][3.1-announcement]
13
15
14
16
---
15
17
@@ -23,7 +25,7 @@ Some reasons you might want to use REST framework:
23
25
*[Authentication policies][authentication] including optional packages for [OAuth1a][oauth1-section] and [OAuth2][oauth2-section].
24
26
*[Serialization][serializers] that supports both [ORM][modelserializer-section] and [non-ORM][serializer-section] data sources.
25
27
* Customizable all the way down - just use [regular function-based views][functionview-section] if you don't need the [more][generic-views][powerful][viewsets][features][routers].
26
-
*[Extensive documentation][index], and [great community support][group].
28
+
*[Extensive documentation][docs], and [great community support][group].
27
29
28
30
There is a live example API for testing purposes, [available here][sandbox].
29
31
@@ -34,7 +36,7 @@ There is a live example API for testing purposes, [available here][sandbox].
34
36
# Requirements
35
37
36
38
* Python (2.6.5+, 2.7, 3.2, 3.3, 3.4)
37
-
* Django (1.4.11+, 1.5.6+, 1.6.3+, 1.7, 1.8-beta)
39
+
* Django (1.4.11+, 1.5.6+, 1.6.3+, 1.7, 1.8)
38
40
39
41
# Installation
40
42
@@ -154,42 +156,15 @@ If you believe you’ve found something in Django REST framework which has secur
154
156
155
157
Send a description of the issue via email to [rest-framework-security@googlegroups.com][security-mail]. The project maintainers will then work with you to resolve any issues where required, prior to any public disclosure.
156
158
157
-
# License
158
-
159
-
Copyright (c) 2011-2015, Tom Christie
160
-
All rights reserved.
161
-
162
-
Redistribution and use in source and binary forms, with or without
163
-
modification, are permitted provided that the following conditions are met:
164
-
165
-
Redistributions of source code must retain the above copyright notice, this
166
-
list of conditions and the following disclaimer.
167
-
Redistributions in binary form must reproduce the above copyright notice, this
168
-
list of conditions and the following disclaimer in the documentation and/or
169
-
other materials provided with the distribution.
170
-
171
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
172
-
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
173
-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
174
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
175
-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
176
-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
177
-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
178
-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
179
-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
180
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Expand all lines: docs/api-guide/authentication.md
+4-1Lines changed: 4 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -168,7 +168,6 @@ The `curl` command line tool may be useful for testing token authenticated APIs.
168
168
If you want every user to have an automatically generated Token, you can simply catch the User's `post_save` signal.
169
169
170
170
from django.conf import settings
171
-
from django.contrib.auth import get_user_model
172
171
from django.db.models.signals import post_save
173
172
from django.dispatch import receiver
174
173
from rest_framework.authtoken.models import Token
@@ -248,6 +247,10 @@ Unauthenticated responses that are denied permission will result in an `HTTP 403
248
247
249
248
If you're using an AJAX style API with SessionAuthentication, you'll need to make sure you include a valid CSRF token for any "unsafe" HTTP method calls, such as `PUT`, `PATCH`, `POST` or `DELETE` requests. See the [Django CSRF documentation][csrf-ajax] for more details.
250
249
250
+
**Warning**: Always use Django's standard login view when creating login pages. This will ensure your login views are properly protected.
251
+
252
+
CSRF validation in REST framework works slightly differently to standard Django due to the need to support both session and non-session based authentication to the same views. This means that only authenticated requests require CSRF tokens, and anonymous requests may be sent without CSRF tokens. This behaviour is not suitable for login views, which should always have CSRF validation applied.
253
+
251
254
# Custom authentication
252
255
253
256
To implement a custom authentication scheme, subclass `BaseAuthentication` and override the `.authenticate(self, request)` method. The method should return a two-tuple of `(user, auth)` if authentication succeeds, or `None` otherwise.
Copy file name to clipboardExpand all lines: docs/api-guide/fields.md
+23-8Lines changed: 23 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,5 @@
1
1
source: fields.py
2
2
3
-
---
4
-
5
-
**Note**: This is the documentation for the **version 3.0** of REST framework. Documentation for [version 2.4](http://tomchristie.github.io/rest-framework-2-docs/) is also available.
6
-
7
-
---
8
-
9
3
# Serializer fields
10
4
11
5
> Each field in a Form class is responsible not only for validating data, but also for "cleaning" it — normalizing it to a consistent format.
@@ -189,6 +183,15 @@ A field that ensures the input is a valid UUID string. The `to_internal_value` m
189
183
190
184
"de305d54-75b4-431b-adb2-eb6b9e546013"
191
185
186
+
**Signature:**`UUIDField(format='hex_verbose')`
187
+
188
+
-`format`: Determines the representation format of the uuid value
189
+
-`'hex_verbose'` - The cannoncical hex representation, including hyphens: `"5ce0e9a5-5ffa-654b-cee0-1238041fb31a"`
190
+
-`'hex'` - The compact hex representation of the UUID, not including hyphens: `"5ce0e9a55ffa654bcee01238041fb31a"`
191
+
-`'int'` - A 128 bit integer representation of the UUID: `"123456789012312313134124512351145145114"`
192
+
-`'urn'` - RFC 4122 URN representation of the UUID: `"urn:uuid:5ce0e9a5-5ffa-654b-cee0-1238041fb31a"`
193
+
Changing the `format` parameters only affects representation values. All formats are accepted by `to_internal_value`
194
+
192
195
## IPAddressField
193
196
194
197
A field that ensures the input is a valid IPv4 or IPv6 string.
@@ -319,6 +322,18 @@ Corresponds to `django.db.models.fields.TimeField`
319
322
320
323
Format strings may either be [Python strftime formats][strftime] which explicitly specify the format, or the special string `'iso-8601'`, which indicates that [ISO 8601][iso8601] style times should be used. (eg `'12:34:56.000000'`)
321
324
325
+
## DurationField
326
+
327
+
A Duration representation.
328
+
Corresponds to `django.db.models.fields.DurationField`
329
+
330
+
The `validated_data` for these fields will contain a `datetime.timedelta` instance.
331
+
The representation is a string following this format `'[DD] [HH:[MM:]]ss[.uuuuuu]'`.
332
+
333
+
**Note:** This field is only available with Django versions >= 1.8.
334
+
335
+
**Signature:**`DurationField()`
336
+
322
337
---
323
338
324
339
# Choice selection fields
@@ -451,7 +466,7 @@ A field class that does not take a value based on user input, but instead takes
451
466
452
467
For example, to include a field that always provides the current time as part of the serializer validated data, you would use the following:
The `HiddenField` class is usually only needed if you have some validation that needs to run based on some pre-provided field values, but you do not want to expose all of those fields to the end user.
457
472
@@ -498,7 +513,7 @@ If you want to create a custom field, you'll need to subclass `Field` and then o
498
513
499
514
The `.to_representation()` method is called to convert the initial datatype into a primitive, serializable datatype.
500
515
501
-
The `to_internal_value()` method is called to restore a primitive datatype into its internal python representation. This method should raise a `serializer.ValidationError` if the data is invalid.
516
+
The `to_internal_value()` method is called to restore a primitive datatype into its internal python representation. This method should raise a `serializers.ValidationError` if the data is invalid.
502
517
503
518
Note that the `WritableField` class that was present in version 2.x no longer exists. You should subclass `Field` and override `to_internal_value()` if the field supports data input.
@@ -395,6 +395,10 @@ The following third party packages provide additional filter implementations.
395
395
396
396
The [django-rest-framework-filters package][django-rest-framework-filters] works together with the `DjangoFilterBackend` class, and allows you to easily create filters across relationships, or create multiple filter lookup types for a given field.
397
397
398
+
## Django REST framework full word search filter
399
+
400
+
The [djangorestframework-word-filter][django-rest-framework-word-search-filter] developed as alternative to `filters.SearchFilter` which will search full word in text, or exact match.
**Note**: This is the documentation for the **version 3.0** of REST framework. Documentation for [version 2.4](http://tomchristie.github.io/rest-framework-2-docs/) is also available.
7
-
8
-
---
9
-
10
4
# Generic views
11
5
12
6
> Django’s generic views... were developed as a shortcut for common usage patterns... They take certain common idioms and patterns found in view development and abstract them so that you can quickly write common views of data without having to repeat yourself.
@@ -57,7 +51,7 @@ For more complex cases you might also want to override various methods on the vi
57
51
58
52
For very simple cases you might want to pass through any class attributes using the `.as_view()` method. For example, your URLconf might include something like the following entry:
@@ -84,10 +78,9 @@ The following attributes control the basic view behavior.
84
78
85
79
The following attributes are used to control pagination when used with list views.
86
80
87
-
*`paginate_by` - The size of pages to use with paginated data. If set to `None` then pagination is turned off. If unset this uses the same value as the `PAGINATE_BY` setting, which defaults to `None`.
88
-
*`paginate_by_param` - The name of a query parameter, which can be used by the client to override the default page size to use for pagination. If unset this uses the same value as the `PAGINATE_BY_PARAM` setting, which defaults to `None`.
89
-
*`pagination_serializer_class` - The pagination serializer class to use when determining the style of paginated responses. Defaults to the same value as the `DEFAULT_PAGINATION_SERIALIZER_CLASS` setting.
90
-
*`page_kwarg` - The name of a URL kwarg or URL query parameter which can be used by the client to control which page is requested. Defaults to `'page'`.
81
+
*`pagination_class` - The pagination class that should be used when paginating list results. Defaults to the same value as the `DEFAULT_PAGINATION_CLASS` setting, which is `'rest_framework.pagination.PageNumberPagination'`.
82
+
83
+
Note that usage of the `paginate_by`, `paginate_by_param` and `page_kwarg` attributes are now pending deprecation. The `pagination_serializer_class` attribute and `DEFAULT_PAGINATION_SERIALIZER_CLASS` setting have been removed completely. Pagination settings should instead be controlled by overriding a pagination class and setting any configuration attributes there. See the pagination documentation for more details.
91
84
92
85
**Filtering**:
93
86
@@ -135,14 +128,14 @@ Note that if your API doesn't include any object level permissions, you may opti
135
128
136
129
Returns the classes that should be used to filter the queryset. Defaults to returning the `filter_backends` attribute.
137
130
138
-
May be overridden to provide more complex behavior with filters, such as using different (or even exlusive) lists of filter_backends depending on different criteria.
131
+
May be overridden to provide more complex behavior with filters, such as using different (or even exclusive) lists of filter_backends depending on different criteria.
139
132
140
133
For example:
141
134
142
135
def get_filter_backends(self):
143
-
if "geo_route" in self.request.QUERY_PARAMS:
136
+
if "geo_route" in self.request.query_params:
144
137
return (GeoRouteFilter, CategoryFilter)
145
-
elif "geo_point" in self.request.QUERY_PARAMS:
138
+
elif "geo_point" in self.request.query_params:
146
139
return (GeoPointFilter, CategoryFilter)
147
140
148
141
return (CategoryFilter,)
@@ -200,7 +193,7 @@ You won't typically need to override the following methods, although you might n
200
193
201
194
*`get_serializer_context(self)` - Returns a dictionary containing any extra context that should be supplied to the serializer. Defaults to including `'request'`, `'view'` and `'format'` keys.
*`get_pagination_serializer(self, page)` - Returns a serializer instance to use with paginated data.
196
+
*`get_paginated_response(self, data)` - Returns a paginated style `Response` object.
204
197
*`paginate_queryset(self, queryset)` - Paginate a queryset if required, either returning a page object, or `None` if pagination is not configured for this view.
205
198
*`filter_queryset(self, queryset)` - Given a queryset, filter it with whichever filter backends are in use, returning a new queryset.
Copy file name to clipboardExpand all lines: docs/api-guide/metadata.md
+1-7Lines changed: 1 addition & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,5 @@
1
1
source: metadata.py
2
2
3
-
---
4
-
5
-
**Note**: This is the documentation for the **version 3.0** of REST framework. Documentation for [version 2.4](http://tomchristie.github.io/rest-framework-2-docs/) is also available.
6
-
7
-
---
8
-
9
3
# Metadata
10
4
11
5
> [The `OPTIONS`] method allows a client to determine the options and/or requirements associated with a resource, or the capabilities of a server, without implying a resource action or initiating a resource retrieval.
@@ -59,7 +53,7 @@ Or you can set the metadata class individually for a view:
0 commit comments