mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-09 08:00:52 +03:00
Merge pull request #334 from minddust/restframework2
formatting docs commits
This commit is contained in:
commit
ab5c28c5f9
|
@ -50,7 +50,7 @@ You can also set the authentication policy on a per-view basis, using the `APIVi
|
||||||
|
|
||||||
Or, if you're using the `@api_view` decorator with function based views.
|
Or, if you're using the `@api_view` decorator with function based views.
|
||||||
|
|
||||||
@api_view(('GET',)),
|
@api_view(['GET'])
|
||||||
@authentication_classes((SessionAuthentication, UserBasicAuthentication))
|
@authentication_classes((SessionAuthentication, UserBasicAuthentication))
|
||||||
@permissions_classes((IsAuthenticated,))
|
@permissions_classes((IsAuthenticated,))
|
||||||
def example_view(request, format=None):
|
def example_view(request, format=None):
|
||||||
|
|
|
@ -37,7 +37,7 @@ You can also set the renderers used for an individual view, using the `APIView`
|
||||||
|
|
||||||
Or, if you're using the `@api_view` decorator with function based views.
|
Or, if you're using the `@api_view` decorator with function based views.
|
||||||
|
|
||||||
@api_view(('POST',)),
|
@api_view(['POST'])
|
||||||
@parser_classes((YAMLParser,))
|
@parser_classes((YAMLParser,))
|
||||||
def example_view(request, format=None):
|
def example_view(request, format=None):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -78,7 +78,7 @@ This permission is suitable if you want your API to only be accessible to regist
|
||||||
|
|
||||||
## IsAdminUser
|
## IsAdminUser
|
||||||
|
|
||||||
The `IsAdminUser` permission class will deny permission to any user, unless `user.is_staff`is `True` in which case permission will be allowed.
|
The `IsAdminUser` permission class will deny permission to any user, unless `user.is_staff` is `True` in which case permission will be allowed.
|
||||||
|
|
||||||
This permission is suitable is you want your API to only be accessible to a subset of trusted administrators.
|
This permission is suitable is you want your API to only be accessible to a subset of trusted administrators.
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ You can also set the renderers used for an individual view, using the `APIView`
|
||||||
|
|
||||||
Or, if you're using the `@api_view` decorator with function based views.
|
Or, if you're using the `@api_view` decorator with function based views.
|
||||||
|
|
||||||
@api_view(('GET',)),
|
@api_view(['GET'])
|
||||||
@renderer_classes((JSONRenderer, JSONPRenderer))
|
@renderer_classes((JSONRenderer, JSONPRenderer))
|
||||||
def user_count_view(request, format=None):
|
def user_count_view(request, format=None):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -135,7 +135,6 @@ Let's look at an example of serializing a class that represents an RGB color val
|
||||||
"""
|
"""
|
||||||
A color represented in the RGB colorspace.
|
A color represented in the RGB colorspace.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, red, green, blue):
|
def __init__(self, red, green, blue):
|
||||||
assert(red >= 0 and green >= 0 and blue >= 0)
|
assert(red >= 0 and green >= 0 and blue >= 0)
|
||||||
assert(red < 256 and green < 256 and blue < 256)
|
assert(red < 256 and green < 256 and blue < 256)
|
||||||
|
@ -145,7 +144,6 @@ Let's look at an example of serializing a class that represents an RGB color val
|
||||||
"""
|
"""
|
||||||
Color objects are serialized into "rgb(#, #, #)" notation.
|
Color objects are serialized into "rgb(#, #, #)" notation.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def to_native(self, obj):
|
def to_native(self, obj):
|
||||||
return "rgb(%d, %d, %d)" % (obj.red, obj.green, obj.blue)
|
return "rgb(%d, %d, %d)" % (obj.red, obj.green, obj.blue)
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ Default:
|
||||||
|
|
||||||
(
|
(
|
||||||
'rest_framework.renderers.JSONRenderer',
|
'rest_framework.renderers.JSONRenderer',
|
||||||
'rest_framework.renderers.BrowsableAPIRenderer'
|
'rest_framework.renderers.BrowsableAPIRenderer',
|
||||||
'rest_framework.renderers.TemplateHTMLRenderer'
|
'rest_framework.renderers.TemplateHTMLRenderer'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,8 @@ The default throttling policy may be set globally, using the `DEFAULT_THROTTLE_C
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_THROTTLE_CLASSES': (
|
'DEFAULT_THROTTLE_CLASSES': (
|
||||||
'rest_framework.throttles.AnonThrottle',
|
'rest_framework.throttles.AnonThrottle',
|
||||||
'rest_framework.throttles.UserThrottle',
|
'rest_framework.throttles.UserThrottle'
|
||||||
)
|
),
|
||||||
'DEFAULT_THROTTLE_RATES': {
|
'DEFAULT_THROTTLE_RATES': {
|
||||||
'anon': '100/day',
|
'anon': '100/day',
|
||||||
'user': '1000/day'
|
'user': '1000/day'
|
||||||
|
@ -102,8 +102,8 @@ For example, multiple user throttle rates could be implemented by using the foll
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_THROTTLE_CLASSES': (
|
'DEFAULT_THROTTLE_CLASSES': (
|
||||||
'example.throttles.BurstRateThrottle',
|
'example.throttles.BurstRateThrottle',
|
||||||
'example.throttles.SustainedRateThrottle',
|
'example.throttles.SustainedRateThrottle'
|
||||||
)
|
),
|
||||||
'DEFAULT_THROTTLE_RATES': {
|
'DEFAULT_THROTTLE_RATES': {
|
||||||
'burst': '60/min',
|
'burst': '60/min',
|
||||||
'sustained': '1000/day'
|
'sustained': '1000/day'
|
||||||
|
@ -136,8 +136,8 @@ For example, given the following views...
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_THROTTLE_CLASSES': (
|
'DEFAULT_THROTTLE_CLASSES': (
|
||||||
'rest_framework.throttles.ScopedRateThrottle',
|
'rest_framework.throttles.ScopedRateThrottle'
|
||||||
)
|
),
|
||||||
'DEFAULT_THROTTLE_RATES': {
|
'DEFAULT_THROTTLE_RATES': {
|
||||||
'contacts': '1000/day',
|
'contacts': '1000/day',
|
||||||
'uploads': '20/day'
|
'uploads': '20/day'
|
||||||
|
|
|
@ -122,7 +122,7 @@ REST framework also allows you to work with regular function based views. It pro
|
||||||
|
|
||||||
## @api_view()
|
## @api_view()
|
||||||
|
|
||||||
**Signature:** `@api_view(http_method_names)
|
**Signature:** `@api_view(http_method_names)`
|
||||||
|
|
||||||
The core of this functionality is the `api_view` decorator, which takes a list of HTTP methods that your view should respond to. For example, this is how you would write a very simple view that just manually returns some data:
|
The core of this functionality is the `api_view` decorator, which takes a list of HTTP methods that your view should respond to. For example, this is how you would write a very simple view that just manually returns some data:
|
||||||
|
|
||||||
|
|
|
@ -87,8 +87,8 @@ For the purposes of this tutorial we're going to start by creating a simple `Sni
|
||||||
default='python',
|
default='python',
|
||||||
max_length=100)
|
max_length=100)
|
||||||
style = models.CharField(choices=STYLE_CHOICES,
|
style = models.CharField(choices=STYLE_CHOICES,
|
||||||
default='friendly',
|
default='friendly',
|
||||||
max_length=100)
|
max_length=100)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ('created',)
|
ordering = ('created',)
|
||||||
|
@ -219,7 +219,6 @@ Edit the `snippet/views.py` file, and add the following.
|
||||||
"""
|
"""
|
||||||
An HttpResponse that renders it's content into JSON.
|
An HttpResponse that renders it's content into JSON.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, data, **kwargs):
|
def __init__(self, data, **kwargs):
|
||||||
content = JSONRenderer().render(data)
|
content = JSONRenderer().render(data)
|
||||||
kwargs['content_type'] = 'application/json'
|
kwargs['content_type'] = 'application/json'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user