From b907a4448572e3c48137e983248fb7411246563a Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Mon, 18 Nov 2013 15:50:29 +0000 Subject: Remove .html suffixes --- tutorial/4-authentication-and-permissions.html | 94 ++++++++++++++------------ 1 file changed, 49 insertions(+), 45 deletions(-) (limited to 'tutorial/4-authentication-and-permissions.html') diff --git a/tutorial/4-authentication-and-permissions.html b/tutorial/4-authentication-and-permissions.html index 5ce9c149..bde22d77 100644 --- a/tutorial/4-authentication-and-permissions.html +++ b/tutorial/4-authentication-and-permissions.html @@ -4,6 +4,7 @@
Because 'snippets' is a reverse relationship on the User model, it will not be included by default when using the ModelSerializer class, so we needed to add an explicit field for it.
We'll also add a couple of views to views.py. We'd like to just use read-only views for the user representations, so we'll use the ListAPIView and RetrieveAPIView generic class based views.
class UserList(generics.ListAPIView):
+from django.contrib.auth.models import User
+
+
+class UserList(generics.ListAPIView):
queryset = User.objects.all()
serializer_class = UserSerializer
@@ -347,7 +351,7 @@ class IsOwnerOrReadOnly(permissions.BasePermission):
Now, if you open a browser again, you find that the 'DELETE' and 'PUT' actions only appear on a snippet instance endpoint if you're logged in as the same user that created the code snippet.
Authenticating with the API
-Because we now have a set of permissions on the API, we need to authenticate our requests to it if we want to edit any snippets. We haven't set up any authentication classes, so the defaults are currently applied, which are SessionAuthentication and BasicAuthentication.
+Because we now have a set of permissions on the API, we need to authenticate our requests to it if we want to edit any snippets. We haven't set up any authentication classes, so the defaults are currently applied, which are SessionAuthentication and BasicAuthentication.
When we interact with the API through the web browser, we can login, and the browser session will then provide the required authentication for the requests.
If we're interacting with the API programmatically we need to explicitly provide the authentication credentials on each request.
If we try to create a snippet without authenticating, we'll get an error:
@@ -362,7 +366,7 @@ class IsOwnerOrReadOnly(permissions.BasePermission):
We've now got a fairly fine-grained set of permissions on our Web API, and end points for users of the system and for the code snippets that they have created.
-In part 5 of the tutorial we'll look at how we can tie everything together by creating an HTML endpoint for our highlighted snippets, and improve the cohesion of our API by using hyperlinking for the relationships within the system.
+In part 5 of the tutorial we'll look at how we can tie everything together by creating an HTML endpoint for our highlighted snippets, and improve the cohesion of our API by using hyperlinking for the relationships within the system.