aboutsummaryrefslogtreecommitdiffstats
path: root/docs/tutorial/4-authentication-and-permissions.md
diff options
context:
space:
mode:
authorTom Christie2014-12-12 15:37:43 +0000
committerTom Christie2014-12-12 15:37:43 +0000
commitbaaa356489dd51d7c68161db40e99cd59b1124c3 (patch)
tree23dc5c4cbe1065580ff88ddd1bfa6dcda956ac68 /docs/tutorial/4-authentication-and-permissions.md
parent5e6052811716a494e995a84c497579867ee6acaa (diff)
parentfd473aa905337908b41c9a1087967a19f0558f89 (diff)
downloaddjango-rest-framework-baaa356489dd51d7c68161db40e99cd59b1124c3.tar.bz2
Merge master
Diffstat (limited to 'docs/tutorial/4-authentication-and-permissions.md')
-rw-r--r--docs/tutorial/4-authentication-and-permissions.md24
1 files changed, 17 insertions, 7 deletions
diff --git a/docs/tutorial/4-authentication-and-permissions.md b/docs/tutorial/4-authentication-and-permissions.md
index 4e4edeea..a6d27bf7 100644
--- a/docs/tutorial/4-authentication-and-permissions.md
+++ b/docs/tutorial/4-authentication-and-permissions.md
@@ -43,7 +43,7 @@ And now we can add a `.save()` method to our model class:
When that's all done we'll need to update our database tables.
Normally we'd create a database migration in order to do that, but for the purposes of this tutorial, let's just delete the database and start again.
- rm tmp.db
+ rm -f tmp.db db.sqlite3
rm -r snippets/migrations
python manage.py makemigrations snippets
python manage.py migrate
@@ -59,7 +59,7 @@ Now that we've got some users to work with, we'd better add representations of t
from django.contrib.auth.models import User
class UserSerializer(serializers.ModelSerializer):
- snippets = serializers.PrimaryKeyRelatedField(many=True)
+ snippets = serializers.PrimaryKeyRelatedField(many=True, queryset=Snippet.objects.all())
class Meta:
model = User
@@ -198,15 +198,25 @@ If we're interacting with the API programmatically we need to explicitly provide
If we try to create a snippet without authenticating, we'll get an error:
- curl -i -X POST http://127.0.0.1:8000/snippets/ -d "code=print 123"
+ http POST http://127.0.0.1:8000/snippets/ code="print 123"
- {"detail": "Authentication credentials were not provided."}
+ {
+ "detail": "Authentication credentials were not provided."
+ }
We can make a successful request by including the username and password of one of the users we created earlier.
- curl -X POST http://127.0.0.1:8000/snippets/ -d "code=print 789" -u tom:password
-
- {"id": 5, "owner": "tom", "title": "foo", "code": "print 789", "linenos": false, "language": "python", "style": "friendly"}
+ http POST -a tom:password http://127.0.0.1:8000/snippets/ code="print 789"
+
+ {
+ "id": 5,
+ "owner": "tom",
+ "title": "foo",
+ "code": "print 789",
+ "linenos": false,
+ "language": "python",
+ "style": "friendly"
+ }
## Summary