aboutsummaryrefslogtreecommitdiffstats
path: root/tutorial
diff options
context:
space:
mode:
Diffstat (limited to 'tutorial')
-rw-r--r--tutorial/1-serialization.html8
-rw-r--r--tutorial/2-requests-and-responses.html8
-rw-r--r--tutorial/3-class-based-views.html2
-rw-r--r--tutorial/4-authentication-and-permissions.html6
-rw-r--r--tutorial/5-relationships-and-hyperlinked-apis.html2
-rw-r--r--tutorial/6-viewsets-and-routers.html2
-rw-r--r--tutorial/quickstart.html2
7 files changed, 13 insertions, 17 deletions
diff --git a/tutorial/1-serialization.html b/tutorial/1-serialization.html
index c75116d3..76c7f818 100644
--- a/tutorial/1-serialization.html
+++ b/tutorial/1-serialization.html
@@ -2,7 +2,7 @@
<html lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
- <title>Django REST framework - Tutorial 1: Serialization</title>
+ <title>Tutorial 1: Serialization - Django REST framework</title>
<link href="http://django-rest-framework.org/img/favicon.ico" rel="icon" type="image/x-icon">
<link rel="canonical" href="http://django-rest-framework.org/tutorial/1-serialization"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -431,8 +431,7 @@ def snippet_list(request):
if serializer.is_valid():
serializer.save()
return JSONResponse(serializer.data, status=201)
- else:
- return JSONResponse(serializer.errors, status=400)
+ return JSONResponse(serializer.errors, status=400)
</code></pre>
<p>Note that because we want to be able to POST to this view from clients that won't have a CSRF token we need to mark the view as <code>csrf_exempt</code>. This isn't something that you'd normally want to do, and REST framework views actually use more sensible behavior than this, but it'll do for our purposes right now. </p>
<p>We'll also need a view which corresponds to an individual snippet, and can be used to retrieve, update or delete the snippet.</p>
@@ -456,8 +455,7 @@ def snippet_detail(request, pk):
if serializer.is_valid():
serializer.save()
return JSONResponse(serializer.data)
- else:
- return JSONResponse(serializer.errors, status=400)
+ return JSONResponse(serializer.errors, status=400)
elif request.method == 'DELETE':
snippet.delete()
diff --git a/tutorial/2-requests-and-responses.html b/tutorial/2-requests-and-responses.html
index 6b5f67da..ef821cec 100644
--- a/tutorial/2-requests-and-responses.html
+++ b/tutorial/2-requests-and-responses.html
@@ -2,7 +2,7 @@
<html lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
- <title>Django REST framework - Tutorial 2: Requests and Responses</title>
+ <title>Tutorial 2: Requests and Responses - Django REST framework</title>
<link href="http://django-rest-framework.org/img/favicon.ico" rel="icon" type="image/x-icon">
<link rel="canonical" href="http://django-rest-framework.org/tutorial/2-requests-and-responses"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -255,8 +255,7 @@ def snippet_list(request):
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
- else:
- return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
+ return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
</code></pre>
<p>Our instance view is an improvement over the previous example. It's a little more concise, and the code now feels very similar to if we were working with the Forms API. We're also using named status codes, which makes the response meanings more obvious.</p>
<p>Here is the view for an individual snippet, in the <code>views.py</code> module.</p>
@@ -279,8 +278,7 @@ def snippet_detail(request, pk):
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
- else:
- return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
+ return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
elif request.method == 'DELETE':
snippet.delete()
diff --git a/tutorial/3-class-based-views.html b/tutorial/3-class-based-views.html
index 6a5ca721..c807ad0f 100644
--- a/tutorial/3-class-based-views.html
+++ b/tutorial/3-class-based-views.html
@@ -2,7 +2,7 @@
<html lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
- <title>Django REST framework - Tutorial 3: Class Based Views</title>
+ <title>Tutorial 3: Class Based Views - Django REST framework</title>
<link href="http://django-rest-framework.org/img/favicon.ico" rel="icon" type="image/x-icon">
<link rel="canonical" href="http://django-rest-framework.org/tutorial/3-class-based-views"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
diff --git a/tutorial/4-authentication-and-permissions.html b/tutorial/4-authentication-and-permissions.html
index 6e166c08..dc1e2212 100644
--- a/tutorial/4-authentication-and-permissions.html
+++ b/tutorial/4-authentication-and-permissions.html
@@ -2,7 +2,7 @@
<html lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
- <title>Django REST framework - Tutorial 4: Authentication & Permissions</title>
+ <title>Tutorial 4: Authentication & Permissions - Django REST framework</title>
<link href="http://django-rest-framework.org/img/favicon.ico" rel="icon" type="image/x-icon">
<link rel="canonical" href="http://django-rest-framework.org/tutorial/4-authentication-and-permissions"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -337,10 +337,10 @@ class IsOwnerOrReadOnly(permissions.BasePermission):
def has_object_permission(self, request, view, obj):
# Read permissions are allowed to any request,
# so we'll always allow GET, HEAD or OPTIONS requests.
- if request.method in permissions.SAFE_METHODS:
+ if request.method in permissions.SAFE_METHODS:
return True
- # Write permissions are only allowed to the owner of the snippet
+ # Write permissions are only allowed to the owner of the snippet.
return obj.owner == request.user
</code></pre>
<p>Now we can add that custom permission to our snippet instance endpoint, by editing the <code>permission_classes</code> property on the <code>SnippetDetail</code> class:</p>
diff --git a/tutorial/5-relationships-and-hyperlinked-apis.html b/tutorial/5-relationships-and-hyperlinked-apis.html
index 9222bc2d..9b0b5c82 100644
--- a/tutorial/5-relationships-and-hyperlinked-apis.html
+++ b/tutorial/5-relationships-and-hyperlinked-apis.html
@@ -2,7 +2,7 @@
<html lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
- <title>Django REST framework - Tutorial 5: Relationships & Hyperlinked APIs</title>
+ <title>Tutorial 5: Relationships & Hyperlinked APIs - Django REST framework</title>
<link href="http://django-rest-framework.org/img/favicon.ico" rel="icon" type="image/x-icon">
<link rel="canonical" href="http://django-rest-framework.org/tutorial/5-relationships-and-hyperlinked-apis"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
diff --git a/tutorial/6-viewsets-and-routers.html b/tutorial/6-viewsets-and-routers.html
index a5287a79..d178e26d 100644
--- a/tutorial/6-viewsets-and-routers.html
+++ b/tutorial/6-viewsets-and-routers.html
@@ -2,7 +2,7 @@
<html lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
- <title>Django REST framework - Tutorial 6: ViewSets & Routers</title>
+ <title>Tutorial 6: ViewSets & Routers - Django REST framework</title>
<link href="http://django-rest-framework.org/img/favicon.ico" rel="icon" type="image/x-icon">
<link rel="canonical" href="http://django-rest-framework.org/tutorial/6-viewsets-and-routers"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
diff --git a/tutorial/quickstart.html b/tutorial/quickstart.html
index 842cacb1..fda9ffdc 100644
--- a/tutorial/quickstart.html
+++ b/tutorial/quickstart.html
@@ -2,7 +2,7 @@
<html lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
- <title>Django REST framework - Quickstart</title>
+ <title>Quickstart - Django REST framework</title>
<link href="http://django-rest-framework.org/img/favicon.ico" rel="icon" type="image/x-icon">
<link rel="canonical" href="http://django-rest-framework.org/tutorial/quickstart"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">