This commit is contained in:
Pravin 2025-10-21 15:20:00 +02:00 committed by GitHub
commit 7dd069cbf2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
26 changed files with 49 additions and 49 deletions

View File

@ -180,7 +180,7 @@ The `allow_null` option is also available for string fields, although its usage
## EmailField
A text representation, validates the text to be a valid e-mail address.
A text representation, validates the text to be a valid email address.
Corresponds to `django.db.models.fields.EmailField`

View File

@ -11,7 +11,7 @@ source:
REST framework supports HTTP content negotiation by providing a `Response` class which allows you to return content that can be rendered into multiple content types, depending on the client request.
The `Response` class subclasses Django's `SimpleTemplateResponse`. `Response` objects are initialised with data, which should consist of native Python primitives. REST framework then uses standard HTTP content negotiation to determine how it should render the final response content.
The `Response` class subclasses Django's `SimpleTemplateResponse`. `Response` objects are initialized with data, which should consist of native Python primitives. REST framework then uses standard HTTP content negotiation to determine how it should render the final response content.
There's no requirement for you to use the `Response` class, you can also return regular `HttpResponse` or `StreamingHttpResponse` objects from your views if required. Using the `Response` class simply provides a nicer interface for returning content-negotiated Web API responses, that can be rendered to multiple formats.

View File

@ -155,7 +155,7 @@ When deserializing data, you always need to call `is_valid()` before attempting
serializer.is_valid()
# False
serializer.errors
# {'email': ['Enter a valid e-mail address.'], 'created': ['This field is required.']}
# {'email': ['Enter a valid email address.'], 'created': ['This field is required.']}
Each key in the dictionary will be the field name, and the values will be lists of strings of any error messages corresponding to that field. The `non_field_errors` key may also be present, and will list any general validation errors. The name of the `non_field_errors` key may be customized using the `NON_FIELD_ERRORS_KEY` REST framework setting.
@ -298,7 +298,7 @@ When dealing with nested representations that support deserializing the data, an
serializer.is_valid()
# False
serializer.errors
# {'user': {'email': ['Enter a valid e-mail address.']}, 'created': ['This field is required.']}
# {'user': {'email': ['Enter a valid email address.']}, 'created': ['This field is required.']}
Similarly, the `.validated_data` property will include nested data structures.

View File

@ -175,7 +175,7 @@ If you want the date field to be entirely hidden from the user, then use `Hidden
Validators that are applied across multiple fields in the serializer can sometimes require a field input that should not be provided by the API client, but that *is* available as input to the validator.
For this purposes use `HiddenField`. This field will be present in `validated_data` but *will not* be used in the serializer output representation.
**Note:** Using a `read_only=True` field is excluded from writable fields so it won't use a `default=…` argument. Look [3.8 announcement](https://www.django-rest-framework.org/community/3.8-announcement/#altered-the-behaviour-of-read_only-plus-default-on-field).
**Note:** Using a `read_only=True` field is excluded from writable fields so it won't use a `default=…` argument. Look [3.8 announcement](https://www.django-rest-framework.org/community/3.8-announcement/#altered-the-behavior-of-read_only-plus-default-on-field).
REST framework includes a couple of defaults that may be useful in this context.

View File

@ -632,7 +632,7 @@ The `MultipleChoiceField` class has been added. This field acts like `ChoiceFiel
The `from_native(self, value)` and `to_native(self, data)` method names have been replaced with the more obviously named `to_internal_value(self, data)` and `to_representation(self, value)`.
The `field_from_native()` and `field_to_native()` methods are removed. Previously you could use these methods if you wanted to customise the behavior in a way that did not simply lookup the field value from the object. For example...
The `field_from_native()` and `field_to_native()` methods are removed. Previously you could use these methods if you wanted to customize the behavior in a way that did not simply lookup the field value from the object. For example...
def field_to_native(self, obj, field_name):
"""A custom read-only field that returns the class name."""

View File

@ -50,7 +50,7 @@ See [the schema documentation](https://www.django-rest-framework.org/api-guide/s
## Customizing the operation ID.
REST framework automatically determines operation IDs to use in OpenAPI
schemas. The latest version provides more control for overriding the behaviour
schemas. The latest version provides more control for overriding the behavior
used to generate the operation IDs.
See [the schema documentation](https://www.django-rest-framework.org/api-guide/schemas/#operationid) for more information.

View File

@ -50,6 +50,6 @@ They must now use the more explicit keyword argument style...
aliases = serializers.ListField(child=serializers.CharField())
```
This change has been made because using positional arguments here *does not* result in the expected behaviour.
This change has been made because using positional arguments here *does not* result in the expected behavior.
See Pull Request [#7632](https://github.com/encode/django-rest-framework/pull/7632) for more details.

View File

@ -39,12 +39,12 @@ By default the URLs created by `SimpleRouter` use regular expressions. This beha
Dependency on pytz has been removed and deprecation warnings have been added, Django will provide ZoneInfo instances as long as USE_DEPRECATED_PYTZ is not enabled. More info on the migration can be found [in this guide](https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html).
## Align `SearchFilter` behaviour to `django.contrib.admin` search
## Align `SearchFilter` behavior to `django.contrib.admin` search
Searches now may contain _quoted phrases_ with spaces, each phrase is considered as a single search term, and it will raise a validation error if any null-character is provided in search. See the [Filtering API guide](../api-guide/filtering.md) for more information.
## Other fixes and improvements
There are a number of fixes and minor improvements in this release, ranging from documentation, internal infrastructure (typing, testing, requirements, deprecation, etc.), security and overall behaviour.
There are a number of fixes and minor improvements in this release, ranging from documentation, internal infrastructure (typing, testing, requirements, deprecation, etc.), security and overall behavior.
See the [release notes](release-notes.md) page for a complete listing.

View File

@ -29,7 +29,7 @@ The current minimum versions of Django is now 4.2 and Python 3.9.
## Django LoginRequiredMiddleware
The new `LoginRequiredMiddleware` introduced by Django 5.1 can now be used alongside Django REST Framework, however it is not honored for API views as an equivalent behaviour can be configured via `DEFAULT_AUTHENTICATION_CLASSES`. See [our dedicated section](../api-guide/authentication.md#django-51-loginrequiredmiddleware) in the docs for more information.
The new `LoginRequiredMiddleware` introduced by Django 5.1 can now be used alongside Django REST Framework, however it is not honored for API views as an equivalent behavior can be configured via `DEFAULT_AUTHENTICATION_CLASSES`. See [our dedicated section](../api-guide/authentication.md#django-51-loginrequiredmiddleware) in the docs for more information.
## Improved support for UniqueConstraint
@ -37,6 +37,6 @@ The generation of validators for [UniqueConstraint](https://docs.djangoproject.c
## Other fixes and improvements
There are a number of fixes and minor improvements in this release, ranging from documentation, internal infrastructure (typing, testing, requirements, deprecation, etc.), security and overall behaviour.
There are a number of fixes and minor improvements in this release, ranging from documentation, internal infrastructure (typing, testing, requirements, deprecation, etc.), security and overall behavior.
See the [release notes](release-notes.md) page for a complete listing.

View File

@ -81,7 +81,7 @@ a dynamic client library to interact with your API.
Finally, we're also now exposing the schema generation as a
[publicly documented API][schema-generation-api], allowing you to more easily
override the behaviour.
override the behavior.
## Requests test client
@ -204,10 +204,10 @@ The `'pk'` identifier in schema paths is now mapped onto the actually model fiel
name by default. This will typically be `'id'`.
This gives a better external representation for schemas, with less implementation
detail being exposed. It also reflects the behaviour of using a ModelSerializer
detail being exposed. It also reflects the behavior of using a ModelSerializer
class with `fields = '__all__'`.
You can revert to the previous behaviour by setting `'SCHEMA_COERCE_PATH_PK': False`
You can revert to the previous behavior by setting `'SCHEMA_COERCE_PATH_PK': False`
in the REST framework settings.
### Schema action name representations
@ -215,7 +215,7 @@ in the REST framework settings.
The internal `retrieve()` and `destroy()` method names are now coerced to an
external representation of `read` and `delete`.
You can revert to the previous behaviour by setting `'SCHEMA_COERCE_METHOD_NAMES': {}`
You can revert to the previous behavior by setting `'SCHEMA_COERCE_METHOD_NAMES': {}`
in the REST framework settings.
### DjangoFilterBackend

View File

@ -53,7 +53,7 @@ In order to try to address this we're now adding the ability for per-view custom
Let's take a quick look at using the new functionality...
The `APIView` class has a `schema` attribute, that is used to control how the Schema for that particular view is generated. The default behaviour is to use the `AutoSchema` class.
The `APIView` class has a `schema` attribute, that is used to control how the Schema for that particular view is generated. The default behavior is to use the `AutoSchema` class.
from rest_framework.views import APIView
from rest_framework.schemas import AutoSchema

View File

@ -36,7 +36,7 @@ If you use REST framework commercially and would like to see this work continue,
## Breaking Changes
### Altered the behaviour of `read_only` plus `default` on Field.
### Altered the behavior of `read_only` plus `default` on Field.
[#5886][gh5886] `read_only` fields will now **always** be excluded from writable fields.
@ -44,7 +44,7 @@ Previously `read_only` fields when combined with a `default` value would use the
operations. This was counter-intuitive in some circumstances and led to difficulties supporting dotted `source`
attributes on nullable relations.
In order to maintain the old behaviour you may need to pass the value of `read_only` fields when calling `save()` in
In order to maintain the old behavior you may need to pass the value of `read_only` fields when calling `save()` in
the view:
def perform_create(self, serializer):

View File

@ -105,7 +105,7 @@ This release fixes a few bugs, clean-up some old code paths for unsupported Pyth
**Date**: 28th March 2025
This release is considered a significant release to improve upstream support with Django and Python. Some of these may change the behaviour of existing features and pre-existing behaviour. Specifically, some fixes were added to around the support of `UniqueConstraint` with nullable fields which will improve built-in serializer validation.
This release is considered a significant release to improve upstream support with Django and Python. Some of these may change the behavior of existing features and pre-existing behavior. Specifically, some fixes were added to around the support of `UniqueConstraint` with nullable fields which will improve built-in serializer validation.
#### Features
@ -215,7 +215,7 @@ Date: 15th March 2024
* Partial serializer should not have required fields [[#7563](https://github.com/encode/django-rest-framework/pull/7563)]
* Propagate 'default' from model field to serializer field. [[#9030](https://github.com/encode/django-rest-framework/pull/9030)]
* Allow to override child.run_validation call in ListSerializer [[#8035](https://github.com/encode/django-rest-framework/pull/8035)]
* Align SearchFilter behaviour to django.contrib.admin search [[#9017](https://github.com/encode/django-rest-framework/pull/9017)]
* Align SearchFilter behavior to django.contrib.admin search [[#9017](https://github.com/encode/django-rest-framework/pull/9017)]
* Class name added to unknown field error [[#9019](https://github.com/encode/django-rest-framework/pull/9019)]
* Fix: Pagination response schemas. [[#9049](https://github.com/encode/django-rest-framework/pull/9049)]
* Fix choices in ChoiceField to support IntEnum [[#8955](https://github.com/encode/django-rest-framework/pull/8955)]
@ -621,13 +621,13 @@ Be sure to upgrade to Python 3 before upgrading to Django REST Framework 3.10.
**Date**: [3rd April 2018][3.8.0-milestone]
* **Breaking Change**: Alter `read_only` plus `default` behaviour. [#5886][gh5886]
* **Breaking Change**: Alter `read_only` plus `default` behavior. [#5886][gh5886]
`read_only` fields will now **always** be excluded from writable fields.
Previously `read_only` fields with a `default` value would use the `default` for create and update operations.
In order to maintain the old behaviour you may need to pass the value of `read_only` fields when calling `save()` in
In order to maintain the old behavior you may need to pass the value of `read_only` fields when calling `save()` in
the view:
def perform_create(self, serializer):
@ -635,13 +635,13 @@ Be sure to upgrade to Python 3 before upgrading to Django REST Framework 3.10.
Alternatively you may override `save()` or `create()` or `update()` on the serializer as appropriate.
* Correct allow_null behaviour when required=False [#5888][gh5888]
* Correct allow_null behavior when required=False [#5888][gh5888]
Without an explicit `default`, `allow_null` implies a default of `null` for outgoing serialization. Previously such
fields were being skipped when read-only or otherwise not required.
**Possible backwards compatibility break** if you were relying on such fields being excluded from the outgoing
representation. In order to restore the old behaviour you can override `data` to exclude the field when `None`.
representation. In order to restore the old behavior you can override `data` to exclude the field when `None`.
For example:
@ -883,7 +883,7 @@ Be sure to upgrade to Python 3 before upgrading to Django REST Framework 3.10.
* Don't strip microseconds from `time` when encoding. Makes consistent with `datetime`.
**BC Change**: Previously only milliseconds were encoded. [#5440][gh5440]
* Added `STRICT_JSON` setting (default `True`) to raise exception for the extended float values (`nan`, `inf`, `-inf`) accepted by Python's `json` module.
**BC Change**: Previously these values would converted to corresponding strings. Set `STRICT_JSON` to `False` to restore the previous behaviour. [#5265][gh5265]
**BC Change**: Previously these values would converted to corresponding strings. Set `STRICT_JSON` to `False` to restore the previous behavior. [#5265][gh5265]
* Add support for `page_size` parameter in CursorPaginator class [#5250][gh5250]
* Make `DEFAULT_PAGINATION_CLASS` `None` by default.
**BC Change**: If your were **just** setting `PAGE_SIZE` to enable pagination you will need to add `DEFAULT_PAGINATION_CLASS`.

View File

@ -181,7 +181,7 @@ The context that's available to the template:
* `FORMAT_PARAM` : The view can accept a format override
* `METHOD_PARAM` : The view can accept a method override
You can override the `BrowsableAPIRenderer.get_context()` method to customise the context that gets passed to the template.
You can override the `BrowsableAPIRenderer.get_context()` method to customize the context that gets passed to the template.
#### Not using base.html

View File

@ -75,7 +75,7 @@ class SearchFilter(BaseFilterBackend):
def get_search_fields(self, view, request):
"""
Search fields are obtained from the view, but the request is always
passed to this method. Sub-classes can override this method to
passed to this method. Subclasses can override this method to
dynamically change the search fields based on request content.
"""
return getattr(view, 'search_fields', None)

View File

@ -1,5 +1,5 @@
"""
Generic views that provide commonly needed behaviour.
Generic views that provide commonly needed behavior.
"""
from django.core.exceptions import ValidationError
from django.db.models.query import QuerySet

View File

@ -1,7 +1,7 @@
"""
Basic building blocks for generic class based views.
We don't bind behaviour to http method handlers yet,
We don't bind behavior to http method handlers yet,
which allows mixin classes to be composed in interesting ways.
"""
from rest_framework import status

View File

@ -50,7 +50,7 @@ Position conflicts with coreapi.Link for URL path {target_url}.
Attempted to insert link with keys: {keys}.
Adjust URLs to avoid naming collision or override `SchemaGenerator.get_keys()`
to customise schema structure.
to customize schema structure.
"""
@ -153,7 +153,7 @@ class SchemaGenerator(BaseSchemaGenerator):
"""
Generate a `coreapi.Document` representing the API schema.
"""
self._initialise_endpoints()
self._initialize_endpoints()
links = self.get_links(None if public else request)
if not links:
@ -513,7 +513,7 @@ class AutoSchema(ViewInspector):
Default implementation looks for ModelViewSet or GenericAPIView
actions/methods that cause filtering on the default implementation.
Override to adjust behaviour for your view.
Override to adjust behavior for your view.
Note: Introduced in v3.7: Initially "private" (i.e. with leading underscore)
to allow changes based on user experience.

View File

@ -165,7 +165,7 @@ class BaseSchemaGenerator:
self.url = url
self.endpoints = None
def _initialise_endpoints(self):
def _initialize_endpoints(self):
if self.endpoints is None:
inspector = self.endpoint_inspector_cls(self.patterns, self.urlconf)
self.endpoints = inspector.get_api_endpoints()

View File

@ -65,7 +65,7 @@ class SchemaGenerator(BaseSchemaGenerator):
"""
Generate a OpenAPI schema.
"""
self._initialise_endpoints()
self._initialize_endpoints()
components_schemas = {}
# Iterate endpoints generating per method path operations.

View File

@ -33,7 +33,7 @@ class AnonymousUserTests(TestCase):
@override_settings(ROOT_URLCONF='tests.browsable_api.auth_urls')
class DropdownWithAuthTests(TestCase):
"""Tests correct dropdown behaviour with Auth views enabled."""
"""Tests correct dropdown behavior with Auth views enabled."""
def setUp(self):
self.client = APIClient(enforce_csrf_checks=True)
self.username = 'john'
@ -74,7 +74,7 @@ class DropdownWithAuthTests(TestCase):
@override_settings(ROOT_URLCONF='tests.browsable_api.no_auth_urls')
class NoDropdownWithoutAuthTests(TestCase):
"""Tests correct dropdown behaviour with Auth views NOT enabled."""
"""Tests correct dropdown behavior with Auth views NOT enabled."""
def setUp(self):
self.client = APIClient(enforce_csrf_checks=True)
self.username = 'john'

View File

@ -28,7 +28,7 @@ urlpatterns = [
class DropdownWithAuthTests(TestCase):
"""Tests correct dropdown behaviour with Auth views enabled."""
"""Tests correct dropdown behavior with Auth views enabled."""
@override_settings(ROOT_URLCONF='tests.browsable_api.test_browsable_nested_api')
def test_login(self):

View File

@ -1149,7 +1149,7 @@ class TestGenerator(TestCase):
path('example/', views.ExampleListView.as_view()),
]
generator = SchemaGenerator(patterns=patterns)
generator._initialise_endpoints()
generator._initialize_endpoints()
paths = generator.get_schema()["paths"]
@ -1166,7 +1166,7 @@ class TestGenerator(TestCase):
path('v1/example/{pk}/', views.ExampleDetailView.as_view()),
]
generator = SchemaGenerator(patterns=patterns)
generator._initialise_endpoints()
generator._initialize_endpoints()
paths = generator.get_schema()["paths"]
@ -1179,7 +1179,7 @@ class TestGenerator(TestCase):
path('example/{pk}/', views.ExampleDetailView.as_view()),
]
generator = SchemaGenerator(patterns=patterns, url='/api')
generator._initialise_endpoints()
generator._initialize_endpoints()
paths = generator.get_schema()["paths"]

View File

@ -332,7 +332,7 @@ class TestInitialWithCallable:
def test_initial_should_accept_callable(self):
"""
Follows the default ``Field.initial`` behaviour where they accept a
Follows the default ``Field.initial`` behavior where they accept a
callable to produce the initial value"""
assert self.serializer.data == {
'initial_field': 123,

View File

@ -52,14 +52,14 @@ class PlainTextParser(BaseParser):
class TestContentParsing(TestCase):
def test_standard_behaviour_determines_no_content_GET(self):
def test_standard_behavior_determines_no_content_GET(self):
"""
Ensure request.data returns empty QueryDict for GET request.
"""
request = Request(factory.get('/'))
assert request.data == {}
def test_standard_behaviour_determines_no_content_HEAD(self):
def test_standard_behavior_determines_no_content_HEAD(self):
"""
Ensure request.data returns empty QueryDict for HEAD request.
"""
@ -105,7 +105,7 @@ class TestContentParsing(TestCase):
assert list(request.POST) == []
assert list(request.FILES) == ['upload']
def test_standard_behaviour_determines_form_content_PUT(self):
def test_standard_behavior_determines_form_content_PUT(self):
"""
Ensure request.data returns content for PUT request with form content.
"""
@ -114,7 +114,7 @@ class TestContentParsing(TestCase):
request.parsers = (FormParser(), MultiPartParser())
assert list(request.data.items()) == list(data.items())
def test_standard_behaviour_determines_non_form_content_PUT(self):
def test_standard_behavior_determines_non_form_content_PUT(self):
"""
Ensure request.data returns content for PUT request with
non-form content.

View File

@ -287,7 +287,7 @@ class TestNestedListSerializer:
class TestNestedListSerializerAllowEmpty:
"""Tests the behaviour of allow_empty=False when a ListSerializer is used as a field."""
"""Tests the behavior of allow_empty=False when a ListSerializer is used as a field."""
@pytest.mark.parametrize('partial', (False, True))
def test_allow_empty_true(self, partial):
@ -643,7 +643,7 @@ class TestSerializerPartialUsage:
class TestEmptyListSerializer:
"""
Tests the behaviour of ListSerializers when there is no data passed to it
Tests the behavior of ListSerializers when there is no data passed to it
"""
def setup_method(self):
@ -672,7 +672,7 @@ class TestEmptyListSerializer:
class TestMaxMinLengthListSerializer:
"""
Tests the behaviour of ListSerializers when max_length and min_length are used
Tests the behavior of ListSerializers when max_length and min_length are used
"""
def setup_method(self):