aboutsummaryrefslogtreecommitdiffstats
path: root/docs/api-guide
diff options
context:
space:
mode:
authorTom Christie2014-11-28 15:55:02 +0000
committerTom Christie2014-11-28 15:55:02 +0000
commit08c727add37790b5a556db3fff762f4a27a5c660 (patch)
tree2845ea324ac0adf914421a289a5272d6c0d2d74a /docs/api-guide
parent3a5b3772fefc3c2f2c0899947cbc07bfe6e6b5d2 (diff)
downloaddjango-rest-framework-08c727add37790b5a556db3fff762f4a27a5c660.tar.bz2
@api_view defaults to allowing GET
Diffstat (limited to 'docs/api-guide')
-rw-r--r--docs/api-guide/views.md15
1 files changed, 11 insertions, 4 deletions
diff --git a/docs/api-guide/views.md b/docs/api-guide/views.md
index 31c62682..291fe737 100644
--- a/docs/api-guide/views.md
+++ b/docs/api-guide/views.md
@@ -127,19 +127,26 @@ REST framework also allows you to work with regular function based views. It pr
## @api_view()
-**Signature:** `@api_view(http_method_names)`
+**Signature:** `@api_view(http_method_names=['GET'])`
-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:
from rest_framework.decorators import api_view
- @api_view(['GET'])
+ @api_view()
def hello_world(request):
return Response({"message": "Hello, world!"})
-
This view will use the default renderers, parsers, authentication classes etc specified in the [settings].
+By default only `GET` methods will be accepted. Other methods will respond with "405 Method Not Allowed". To alter this behavior, specify which methods the view allows, like so:
+
+ @api_view(['GET', 'POST'])
+ def hello_world(request):
+ if request.method == 'POST':
+ return Response({"message": "Got some data!", "data": request.data})
+ return Response({"message": "Hello, world!"})
+
## API policy decorators
To override the default settings, REST framework provides a set of additional decorators which can be added to your views. These must come *after* (below) the `@api_view` decorator. For example, to create a view that uses a [throttle][throttling] to ensure it can only be called once per day by a particular user, use the `@throttle_classes` decorator, passing a list of throttle classes: