mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-04-25 11:33:43 +03:00
Docs: Convert all tabs into spaces (#8692)
This commit is contained in:
parent
56946fac8f
commit
20d347a806
|
@ -338,7 +338,7 @@ If the `.authenticate_header()` method is not overridden, the authentication sch
|
||||||
|
|
||||||
The following example will authenticate any incoming request as the user given by the username in a custom request header named 'X-USERNAME'.
|
The following example will authenticate any incoming request as the user given by the username in a custom request header named 'X-USERNAME'.
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from rest_framework import authentication
|
from rest_framework import authentication
|
||||||
from rest_framework import exceptions
|
from rest_framework import exceptions
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ The default content negotiation class may be set globally, using the `DEFAULT_CO
|
||||||
|
|
||||||
You can also set the content negotiation used for an individual view, or viewset, using the `APIView` class-based views.
|
You can also set the content negotiation used for an individual view, or viewset, using the `APIView` class-based views.
|
||||||
|
|
||||||
from myapp.negotiation import IgnoreClientContentNegotiation
|
from myapp.negotiation import IgnoreClientContentNegotiation
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
|
|
|
@ -32,16 +32,16 @@ You should **include the request as a keyword argument** to the function, for ex
|
||||||
|
|
||||||
from rest_framework.reverse import reverse
|
from rest_framework.reverse import reverse
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
|
|
||||||
class APIRootView(APIView):
|
class APIRootView(APIView):
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
year = now().year
|
year = now().year
|
||||||
data = {
|
data = {
|
||||||
...
|
...
|
||||||
'year-summary-url': reverse('year-summary', args=[year], request=request)
|
'year-summary-url': reverse('year-summary', args=[year], request=request)
|
||||||
}
|
}
|
||||||
return Response(data)
|
return Response(data)
|
||||||
|
|
||||||
## reverse_lazy
|
## reverse_lazy
|
||||||
|
|
||||||
|
|
|
@ -910,7 +910,7 @@ We can now use this class to serialize single `HighScore` instances:
|
||||||
def high_score(request, pk):
|
def high_score(request, pk):
|
||||||
instance = HighScore.objects.get(pk=pk)
|
instance = HighScore.objects.get(pk=pk)
|
||||||
serializer = HighScoreSerializer(instance)
|
serializer = HighScoreSerializer(instance)
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
||||||
Or use it to serialize multiple instances:
|
Or use it to serialize multiple instances:
|
||||||
|
|
||||||
|
@ -918,7 +918,7 @@ Or use it to serialize multiple instances:
|
||||||
def all_high_scores(request):
|
def all_high_scores(request):
|
||||||
queryset = HighScore.objects.order_by('-score')
|
queryset = HighScore.objects.order_by('-score')
|
||||||
serializer = HighScoreSerializer(queryset, many=True)
|
serializer = HighScoreSerializer(queryset, many=True)
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
||||||
#### Read-write `BaseSerializer` classes
|
#### Read-write `BaseSerializer` classes
|
||||||
|
|
||||||
|
@ -949,8 +949,8 @@ Here's a complete example of our previous `HighScoreSerializer`, that's been upd
|
||||||
'player_name': 'May not be more than 10 characters.'
|
'player_name': 'May not be more than 10 characters.'
|
||||||
})
|
})
|
||||||
|
|
||||||
# Return the validated values. This will be available as
|
# Return the validated values. This will be available as
|
||||||
# the `.validated_data` property.
|
# the `.validated_data` property.
|
||||||
return {
|
return {
|
||||||
'score': int(score),
|
'score': int(score),
|
||||||
'player_name': player_name
|
'player_name': player_name
|
||||||
|
|
|
@ -50,9 +50,9 @@ The rate descriptions used in `DEFAULT_THROTTLE_RATES` may include `second`, `mi
|
||||||
You can also set the throttling policy on a per-view or per-viewset basis,
|
You can also set the throttling policy on a per-view or per-viewset basis,
|
||||||
using the `APIView` class-based views.
|
using the `APIView` class-based views.
|
||||||
|
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.throttling import UserRateThrottle
|
from rest_framework.throttling import UserRateThrottle
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
class ExampleView(APIView):
|
class ExampleView(APIView):
|
||||||
throttle_classes = [UserRateThrottle]
|
throttle_classes = [UserRateThrottle]
|
||||||
|
|
|
@ -30,12 +30,12 @@ in the URL path.
|
||||||
|
|
||||||
For example...
|
For example...
|
||||||
|
|
||||||
Method | Path | Tags
|
Method | Path | Tags
|
||||||
--------------------------------|-----------------|-------------
|
--------------------------------|-----------------|-------------
|
||||||
`GET`, `PUT`, `PATCH`, `DELETE` | `/users/{id}/` | `['users']`
|
`GET`, `PUT`, `PATCH`, `DELETE` | `/users/{id}/` | `['users']`
|
||||||
`GET`, `POST` | `/users/` | `['users']`
|
`GET`, `POST` | `/users/` | `['users']`
|
||||||
`GET`, `PUT`, `PATCH`, `DELETE` | `/orders/{id}/` | `['orders']`
|
`GET`, `PUT`, `PATCH`, `DELETE` | `/orders/{id}/` | `['orders']`
|
||||||
`GET`, `POST` | `/orders/` | `['orders']`
|
`GET`, `POST` | `/orders/` | `['orders']`
|
||||||
|
|
||||||
The tags used for a particular view may also be overridden...
|
The tags used for a particular view may also be overridden...
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user