From e2ea98e8ab3192fa8d252d33cc03929fcf6ed02f Mon Sep 17 00:00:00 2001 From: Tymur Maryokhin Date: Sat, 29 Nov 2014 20:23:55 +0100 Subject: Fixed typos --- docs/tutorial/6-viewsets-and-routers.md | 4 ++-- docs/tutorial/quickstart.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'docs/tutorial') diff --git a/docs/tutorial/6-viewsets-and-routers.md b/docs/tutorial/6-viewsets-and-routers.md index 3fad509a..816e9da6 100644 --- a/docs/tutorial/6-viewsets-and-routers.md +++ b/docs/tutorial/6-viewsets-and-routers.md @@ -112,7 +112,7 @@ Here's our re-wired `urls.py` file. router.register(r'users', views.UserViewSet) # The API URLs are now determined automatically by the router. - # Additionally, we include the login URLs for the browseable API. + # Additionally, we include the login URLs for the browsable API. urlpatterns = [ url(r'^', include(router.urls)), url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')) @@ -130,7 +130,7 @@ That doesn't mean it's always the right approach to take. There's a similar set ## Reviewing our work -With an incredibly small amount of code, we've now got a complete pastebin Web API, which is fully web browseable, and comes complete with authentication, per-object permissions, and multiple renderer formats. +With an incredibly small amount of code, we've now got a complete pastebin Web API, which is fully web browsable, and comes complete with authentication, per-object permissions, and multiple renderer formats. We've walked through each step of the design process, and seen how if we need to customize anything we can gradually work our way down to simply using regular Django views. diff --git a/docs/tutorial/quickstart.md b/docs/tutorial/quickstart.md index 1c398c1f..3e1ce0a9 100644 --- a/docs/tutorial/quickstart.md +++ b/docs/tutorial/quickstart.md @@ -100,7 +100,7 @@ Okay, now let's wire up the API URLs. On to `tutorial/urls.py`... router.register(r'groups', views.GroupViewSet) # Wire up our API using automatic URL routing. - # Additionally, we include login URLs for the browseable API. + # Additionally, we include login URLs for the browsable API. urlpatterns = [ url(r'^', include(router.urls)), url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')) -- cgit v1.2.3 From 34b5db62e560e73516fb569eaf9b71ea5562958f Mon Sep 17 00:00:00 2001 From: phalt Date: Mon, 1 Dec 2014 13:39:53 +0000 Subject: Use httpie for tutorials --- docs/tutorial/1-serialization.md | 48 +++++++++++++++++--- docs/tutorial/2-requests-and-responses.md | 55 ++++++++++++++++++----- docs/tutorial/4-authentication-and-permissions.md | 20 ++++++--- docs/tutorial/quickstart.md | 29 ++++++++++++ 4 files changed, 129 insertions(+), 23 deletions(-) (limited to 'docs/tutorial') diff --git a/docs/tutorial/1-serialization.md b/docs/tutorial/1-serialization.md index a3c19858..3ef65116 100644 --- a/docs/tutorial/1-serialization.md +++ b/docs/tutorial/1-serialization.md @@ -332,17 +332,51 @@ Quit out of the shell... In another terminal window, we can test the server. -We can get a list of all of the snippets. +We could use `curl`, but let's use a nicer tool called [httpie][httpie] to test our server. It has much nicer formatting and makes our output easier to read. This is especially useful when testing. - curl http://127.0.0.1:8000/snippets/ +You can install httpie on all operating systems using pip: - [{"id": 1, "title": "", "code": "foo = \"bar\"\n", "linenos": false, "language": "python", "style": "friendly"}, {"id": 2, "title": "", "code": "print \"hello, world\"\n", "linenos": false, "language": "python", "style": "friendly"}] + pip install httpie -Or we can get a particular snippet by referencing its id. +It can also be installed through [Homebrew][brew] on Mac: - curl http://127.0.0.1:8000/snippets/2/ + brew install httpie - {"id": 2, "title": "", "code": "print \"hello, world\"\n", "linenos": false, "language": "python", "style": "friendly"} +Finally, we can get a list of all of the snippets: + + http http://127.0.0.1:8000/snippets/ --body + + [ + { + "id": 1, + "title": "", + "code": "foo = \"bar\"\n", + "linenos": false, + "language": "python", + "style": "friendly" + }, + { + "id": 2, + "title": "", + "code": "print \"hello, world\"\n", + "linenos": false, + "language": "python", + "style": "friendly" + } + ] + +Or we can get a particular snippet by referencing its id: + + http http://127.0.0.1:8000/snippets/2/ --body + + { + "id": 2, + "title": "", + "code": "print \"hello, world\"\n", + "linenos": false, + "language": "python", + "style": "friendly" + } Similarly, you can have the same json displayed by visiting these URLs in a web browser. @@ -359,3 +393,5 @@ We'll see how we can start to improve things in [part 2 of the tutorial][tut-2]. [sandbox]: http://restframework.herokuapp.com/ [virtualenv]: http://www.virtualenv.org/en/latest/index.html [tut-2]: 2-requests-and-responses.md +[httpie]: https://github.com/jakubroztocil/httpie#installation +[brew]: http://brew.sh diff --git a/docs/tutorial/2-requests-and-responses.md b/docs/tutorial/2-requests-and-responses.md index f377c712..dcaf7c0c 100644 --- a/docs/tutorial/2-requests-and-responses.md +++ b/docs/tutorial/2-requests-and-responses.md @@ -127,31 +127,62 @@ Go ahead and test the API from the command line, as we did in [tutorial part 1][ We can get a list of all of the snippets, as before. - curl http://127.0.0.1:8000/snippets/ - - [{"id": 1, "title": "", "code": "foo = \"bar\"\n", "linenos": false, "language": "python", "style": "friendly"}, {"id": 2, "title": "", "code": "print \"hello, world\"\n", "linenos": false, "language": "python", "style": "friendly"}] + http http://127.0.0.1:8000/snippets/ --body + + [ + { + "id": 1, + "title": "", + "code": "foo = \"bar\"\n", + "linenos": false, + "language": "python", + "style": "friendly" + }, + { + "id": 2, + "title": "", + "code": "print \"hello, world\"\n", + "linenos": false, + "language": "python", + "style": "friendly" + } + ] We can control the format of the response that we get back, either by using the `Accept` header: - curl http://127.0.0.1:8000/snippets/ -H 'Accept: application/json' # Request JSON - curl http://127.0.0.1:8000/snippets/ -H 'Accept: text/html' # Request HTML + http http://127.0.0.1:8000/snippets/ Accept:application/json # Request JSON + http http://127.0.0.1:8000/snippets/ Accept:text/html # Request HTML Or by appending a format suffix: - curl http://127.0.0.1:8000/snippets/.json # JSON suffix - curl http://127.0.0.1:8000/snippets/.api # Browsable API suffix + http http://127.0.0.1:8000/snippets/.json # JSON suffix + http http://127.0.0.1:8000/snippets/.api # Browsable API suffix Similarly, we can control the format of the request that we send, using the `Content-Type` header. # POST using form data - curl -X POST http://127.0.0.1:8000/snippets/ -d "code=print 123" + http --form POST http://127.0.0.1:8000/snippets/ code="print 123" - {"id": 3, "title": "", "code": "print 123", "linenos": false, "language": "python", "style": "friendly"} + { + "id": 3, + "title": "", + "code": "print 123", + "linenos": false, + "language": "python", + "style": "friendly" + } # POST using JSON - curl -X POST http://127.0.0.1:8000/snippets/ -d '{"code": "print 456"}' -H "Content-Type: application/json" - - {"id": 4, "title": "", "code": "print 456", "linenos": true, "language": "python", "style": "friendly"} + http --json POST http://127.0.0.1:8000/snippets/ code="print 456" + + { + "id": 4, + "title": "", + "code": "print 456", + "linenos": true, + "language": "python", + "style": "friendly" + } Now go and open the API in a web browser, by visiting [http://127.0.0.1:8000/snippets/][devserver]. diff --git a/docs/tutorial/4-authentication-and-permissions.md b/docs/tutorial/4-authentication-and-permissions.md index 4e4edeea..15d93a62 100644 --- a/docs/tutorial/4-authentication-and-permissions.md +++ b/docs/tutorial/4-authentication-and-permissions.md @@ -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 diff --git a/docs/tutorial/quickstart.md b/docs/tutorial/quickstart.md index 1c398c1f..41e864cc 100644 --- a/docs/tutorial/quickstart.md +++ b/docs/tutorial/quickstart.md @@ -24,6 +24,10 @@ Create a new Django project named `tutorial`, then start a new app called `quick django-admin.py startapp quickstart cd .. +Optionally, install [httpie][httpie] for tastier HTTP requests: + + pip install httpie + Now sync your database for the first time: python manage.py migrate @@ -159,6 +163,30 @@ We can now access our API, both from the command-line, using tools like `curl`.. ] } +Or with [httpie][httpie], a tastier version of `curl`... + + bash: http -a username:password http://127.0.0.1:8000/users/ --body + { + "count": 2, + "next": null, + "previous": null, + "results": [ + { + "email": "admin@example.com", + "groups": [], + "url": "http://localhost:8000/users/1/", + "username": "paul" + }, + { + "email": "tom@example.com", + "groups": [ ], + "url": "http://127.0.0.1:8000/users/2/", + "username": "tom" + } + ] + } + + Or directly through the browser... ![Quick start image][image] @@ -173,3 +201,4 @@ If you want to get a more in depth understanding of how REST framework fits toge [image]: ../img/quickstart.png [tutorial]: 1-serialization.md [guide]: ../#api-guide +[httpie]: https://github.com/jakubroztocil/httpie#installation -- cgit v1.2.3 From 515060a6ab71e1ef22f4a1e03cb23dbad28a7b23 Mon Sep 17 00:00:00 2001 From: phalt Date: Tue, 2 Dec 2014 10:16:41 +0000 Subject: Only show pip install for httpie --- docs/tutorial/1-serialization.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'docs/tutorial') diff --git a/docs/tutorial/1-serialization.md b/docs/tutorial/1-serialization.md index 3ef65116..dc4fddf9 100644 --- a/docs/tutorial/1-serialization.md +++ b/docs/tutorial/1-serialization.md @@ -332,16 +332,12 @@ Quit out of the shell... In another terminal window, we can test the server. -We could use `curl`, but let's use a nicer tool called [httpie][httpie] to test our server. It has much nicer formatting and makes our output easier to read. This is especially useful when testing. +We can test our API using using `curl` or [httpie][httpie]. Httpie is a user friendly http client that's written in Python. Let's install that. You can install httpie on all operating systems using pip: pip install httpie -It can also be installed through [Homebrew][brew] on Mac: - - brew install httpie - Finally, we can get a list of all of the snippets: http http://127.0.0.1:8000/snippets/ --body -- cgit v1.2.3 From a17d5d2b0bff535dc1d7dcbd36947648e7a0511f Mon Sep 17 00:00:00 2001 From: phalt Date: Tue, 2 Dec 2014 16:11:43 +0000 Subject: remove unsused link --- docs/tutorial/1-serialization.md | 1 - 1 file changed, 1 deletion(-) (limited to 'docs/tutorial') diff --git a/docs/tutorial/1-serialization.md b/docs/tutorial/1-serialization.md index dc4fddf9..ba2a0c32 100644 --- a/docs/tutorial/1-serialization.md +++ b/docs/tutorial/1-serialization.md @@ -390,4 +390,3 @@ We'll see how we can start to improve things in [part 2 of the tutorial][tut-2]. [virtualenv]: http://www.virtualenv.org/en/latest/index.html [tut-2]: 2-requests-and-responses.md [httpie]: https://github.com/jakubroztocil/httpie#installation -[brew]: http://brew.sh -- cgit v1.2.3 From ab25d706c78627dfd582fe9d142ada510c4d6d90 Mon Sep 17 00:00:00 2001 From: Martin Tschammer Date: Wed, 3 Dec 2014 23:52:35 +0100 Subject: Renamed validated_attrs to validated_data to be more in line with other similar code. --- docs/tutorial/1-serialization.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'docs/tutorial') diff --git a/docs/tutorial/1-serialization.md b/docs/tutorial/1-serialization.md index a3c19858..52c75d2c 100644 --- a/docs/tutorial/1-serialization.md +++ b/docs/tutorial/1-serialization.md @@ -110,21 +110,21 @@ The first thing we need to get started on our Web API is to provide a way of ser style = serializers.ChoiceField(choices=STYLE_CHOICES, default='friendly') - def create(self, validated_attrs): + def create(self, validated_data): """ Create and return a new `Snippet` instance, given the validated data. """ - return Snippet.objects.create(**validated_attrs) + return Snippet.objects.create(**validated_data) - def update(self, instance, validated_attrs): + def update(self, instance, validated_data): """ Update and return an existing `Snippet` instance, given the validated data. """ - instance.title = validated_attrs.get('title', instance.title) - instance.code = validated_attrs.get('code', instance.code) - instance.linenos = validated_attrs.get('linenos', instance.linenos) - instance.language = validated_attrs.get('language', instance.language) - instance.style = validated_attrs.get('style', instance.style) + instance.title = validated_data.get('title', instance.title) + instance.code = validated_data.get('code', instance.code) + instance.linenos = validated_data.get('linenos', instance.linenos) + instance.language = validated_data.get('language', instance.language) + instance.style = validated_data.get('style', instance.style) instance.save() return instance -- cgit v1.2.3 From fcbae5d99f93a28c9aac340bf2d4d2a3930e1a6a Mon Sep 17 00:00:00 2001 From: phalt Date: Thu, 4 Dec 2014 11:20:33 +0000 Subject: updates based on suggestions --- docs/tutorial/1-serialization.md | 9 ++++++--- docs/tutorial/2-requests-and-responses.md | 4 +++- docs/tutorial/quickstart.md | 11 +++++------ 3 files changed, 14 insertions(+), 10 deletions(-) (limited to 'docs/tutorial') diff --git a/docs/tutorial/1-serialization.md b/docs/tutorial/1-serialization.md index ba2a0c32..5b1ae6e8 100644 --- a/docs/tutorial/1-serialization.md +++ b/docs/tutorial/1-serialization.md @@ -332,9 +332,9 @@ Quit out of the shell... In another terminal window, we can test the server. -We can test our API using using `curl` or [httpie][httpie]. Httpie is a user friendly http client that's written in Python. Let's install that. +We can test our API using using [curl][curl] or [httpie][httpie]. Httpie is a user friendly http client that's written in Python. Let's install that. -You can install httpie on all operating systems using pip: +You can install httpie using pip: pip install httpie @@ -363,8 +363,10 @@ Finally, we can get a list of all of the snippets: Or we can get a particular snippet by referencing its id: - http http://127.0.0.1:8000/snippets/2/ --body + http http://127.0.0.1:8000/snippets/2/ + HTTP/1.1 200 OK + ... { "id": 2, "title": "", @@ -390,3 +392,4 @@ We'll see how we can start to improve things in [part 2 of the tutorial][tut-2]. [virtualenv]: http://www.virtualenv.org/en/latest/index.html [tut-2]: 2-requests-and-responses.md [httpie]: https://github.com/jakubroztocil/httpie#installation +[curl]: http://curl.haxx.se diff --git a/docs/tutorial/2-requests-and-responses.md b/docs/tutorial/2-requests-and-responses.md index dcaf7c0c..08746cd7 100644 --- a/docs/tutorial/2-requests-and-responses.md +++ b/docs/tutorial/2-requests-and-responses.md @@ -127,8 +127,10 @@ Go ahead and test the API from the command line, as we did in [tutorial part 1][ We can get a list of all of the snippets, as before. - http http://127.0.0.1:8000/snippets/ --body + http http://127.0.0.1:8000/snippets/ + HTTP/1.1 200 OK + ... [ { "id": 1, diff --git a/docs/tutorial/quickstart.md b/docs/tutorial/quickstart.md index 41e864cc..43220ce8 100644 --- a/docs/tutorial/quickstart.md +++ b/docs/tutorial/quickstart.md @@ -24,10 +24,6 @@ Create a new Django project named `tutorial`, then start a new app called `quick django-admin.py startapp quickstart cd .. -Optionally, install [httpie][httpie] for tastier HTTP requests: - - pip install httpie - Now sync your database for the first time: python manage.py migrate @@ -163,9 +159,12 @@ We can now access our API, both from the command-line, using tools like `curl`.. ] } -Or with [httpie][httpie], a tastier version of `curl`... +Or using the [httpie][httpie], command line tool... + + bash: http -a username:password http://127.0.0.1:8000/users/ - bash: http -a username:password http://127.0.0.1:8000/users/ --body + HTTP/1.1 200 OK + ... { "count": 2, "next": null, -- cgit v1.2.3 From 38e05e66c932fc2967cefbd88225bcdc2b0313a7 Mon Sep 17 00:00:00 2001 From: Xavier Ordoquy Date: Thu, 4 Dec 2014 23:22:00 +0100 Subject: print() function works from Python 2.6 to 3.X --- docs/tutorial/1-serialization.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/tutorial') diff --git a/docs/tutorial/1-serialization.md b/docs/tutorial/1-serialization.md index 52c75d2c..b704996d 100644 --- a/docs/tutorial/1-serialization.md +++ b/docs/tutorial/1-serialization.md @@ -210,7 +210,7 @@ One nice property that serializers have is that you can inspect all the fields i >>> from snippets.serializers import SnippetSerializer >>> serializer = SnippetSerializer() - >>> print repr(serializer) # In python 3 use `print(repr(serializer))` + >>> print(repr(serializer)) SnippetSerializer(): id = IntegerField(label='ID', read_only=True) title = CharField(allow_blank=True, max_length=100, required=False) -- cgit v1.2.3 From 9d078be59ca5067d098263b1892740b44f7c41ee Mon Sep 17 00:00:00 2001 From: Xavier Ordoquy Date: Thu, 4 Dec 2014 23:34:55 +0100 Subject: Fix the tutorial against the v3.0 --- docs/tutorial/1-serialization.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'docs/tutorial') diff --git a/docs/tutorial/1-serialization.md b/docs/tutorial/1-serialization.md index b704996d..eb0a00c0 100644 --- a/docs/tutorial/1-serialization.md +++ b/docs/tutorial/1-serialization.md @@ -101,7 +101,7 @@ The first thing we need to get started on our Web API is to provide a way of ser class SnippetSerializer(serializers.Serializer): pk = serializers.IntegerField(read_only=True) - title = serializers.CharField(required=False, + title = serializers.CharField(required=False, allow_blank=True max_length=100) code = serializers.CharField(style={'type': 'textarea'}) linenos = serializers.BooleanField(required=False) @@ -181,7 +181,7 @@ Deserialization is similar. First we parse a stream into Python native datatype serializer = SnippetSerializer(data=data) serializer.is_valid() # True - serializer.object + serializer.save() # Notice how similar the API is to working with forms. The similarity should become even more apparent when we start writing views that use our serializer. @@ -301,7 +301,7 @@ We'll also need a view which corresponds to an individual snippet, and can be us Finally we need to wire these views up. Create the `snippets/urls.py` file: - from django.conf.urls import patterns, url + from django.conf.urls import url from snippets import views urlpatterns = [ -- cgit v1.2.3 From e2b39088345e564a06ce332b740215600c29e481 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Fri, 5 Dec 2014 09:44:01 +0000 Subject: Fix quickstart tutorial --- docs/tutorial/quickstart.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'docs/tutorial') diff --git a/docs/tutorial/quickstart.md b/docs/tutorial/quickstart.md index 3e1ce0a9..d0703381 100644 --- a/docs/tutorial/quickstart.md +++ b/docs/tutorial/quickstart.md @@ -19,10 +19,9 @@ Create a new Django project named `tutorial`, then start a new app called `quick pip install djangorestframework # Set up a new project with a single application - django-admin.py startproject tutorial + django-admin.py startproject tutorial . cd tutorial django-admin.py startapp quickstart - cd .. Now sync your database for the first time: -- cgit v1.2.3 From 1b8c06aefe33f178610d2c4195a72637757698e8 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Fri, 5 Dec 2014 12:46:08 +0000 Subject: Style tweaks in examples --- docs/tutorial/1-serialization.md | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'docs/tutorial') diff --git a/docs/tutorial/1-serialization.md b/docs/tutorial/1-serialization.md index eb0a00c0..fc1b87f9 100644 --- a/docs/tutorial/1-serialization.md +++ b/docs/tutorial/1-serialization.md @@ -16,7 +16,6 @@ The tutorial is fairly in-depth, so you should probably get a cookie and a cup o Before we do anything else we'll create a new virtual environment, using [virtualenv]. This will make sure our package configuration is kept nicely isolated from any other projects we're working on. - :::bash virtualenv env source env/bin/activate @@ -75,12 +74,8 @@ For the purposes of this tutorial we're going to start by creating a simple `Sni title = models.CharField(max_length=100, blank=True, default='') code = models.TextField() linenos = models.BooleanField(default=False) - language = models.CharField(choices=LANGUAGE_CHOICES, - default='python', - max_length=100) - style = models.CharField(choices=STYLE_CHOICES, - default='friendly', - max_length=100) + language = models.CharField(choices=LANGUAGE_CHOICES, default='python', max_length=100) + style = models.CharField(choices=STYLE_CHOICES, default='friendly', max_length=100) class Meta: ordering = ('created',) @@ -101,14 +96,11 @@ The first thing we need to get started on our Web API is to provide a way of ser class SnippetSerializer(serializers.Serializer): pk = serializers.IntegerField(read_only=True) - title = serializers.CharField(required=False, allow_blank=True - max_length=100) + title = serializers.CharField(required=False, allow_blank=True, max_length=100) code = serializers.CharField(style={'type': 'textarea'}) linenos = serializers.BooleanField(required=False) - language = serializers.ChoiceField(choices=LANGUAGE_CHOICES, - default='python') - style = serializers.ChoiceField(choices=STYLE_CHOICES, - default='friendly') + language = serializers.ChoiceField(choices=LANGUAGE_CHOICES, default='python') + style = serializers.ChoiceField(choices=STYLE_CHOICES, default='friendly') def create(self, validated_data): """ -- cgit v1.2.3 From b7b0fd3e146648ba2dc03621edd979abaebcb3b3 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Fri, 5 Dec 2014 12:48:12 +0000 Subject: Added .validated_data usage. Closes #2214. --- docs/tutorial/1-serialization.md | 2 ++ 1 file changed, 2 insertions(+) (limited to 'docs/tutorial') diff --git a/docs/tutorial/1-serialization.md b/docs/tutorial/1-serialization.md index fc1b87f9..3621f01b 100644 --- a/docs/tutorial/1-serialization.md +++ b/docs/tutorial/1-serialization.md @@ -173,6 +173,8 @@ Deserialization is similar. First we parse a stream into Python native datatype serializer = SnippetSerializer(data=data) serializer.is_valid() # True + serializer.validated_data + # OrderedDict([('title', ''), ('code', 'print "hello, world"\n'), ('linenos', False), ('language', 'python'), ('style', 'friendly')]) serializer.save() # -- cgit v1.2.3 From e4820d611bb17e33bf466c2a6dedcce7548d8d21 Mon Sep 17 00:00:00 2001 From: Xavier Ordoquy Date: Sat, 6 Dec 2014 10:53:24 +0100 Subject: Fix the new Django default db name PrimaryKeyRelatedField now needs a queryset argument. urls now don't use urlpatterns. --- docs/tutorial/4-authentication-and-permissions.md | 4 ++-- docs/tutorial/5-relationships-and-hyperlinked-apis.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'docs/tutorial') diff --git a/docs/tutorial/4-authentication-and-permissions.md b/docs/tutorial/4-authentication-and-permissions.md index 4e4edeea..43c1953e 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 diff --git a/docs/tutorial/5-relationships-and-hyperlinked-apis.md b/docs/tutorial/5-relationships-and-hyperlinked-apis.md index 50552616..58422929 100644 --- a/docs/tutorial/5-relationships-and-hyperlinked-apis.md +++ b/docs/tutorial/5-relationships-and-hyperlinked-apis.md @@ -44,7 +44,7 @@ Instead of using a concrete generic view, we'll use the base class for represent As usual we need to add the new views that we've created in to our URLconf. We'll add a url pattern for our new API root in `snippets/urls.py`: - url(r'^$', 'api_root'), + url(r'^$', views.api_root), And then add a url pattern for the snippet highlights: -- cgit v1.2.3 From 8e9408115d0a3ab433078b82c9cc51f825eeac71 Mon Sep 17 00:00:00 2001 From: phalt Date: Mon, 8 Dec 2014 15:41:01 +0000 Subject: fixed indentations --- docs/tutorial/1-serialization.md | 8 +++++--- docs/tutorial/2-requests-and-responses.md | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'docs/tutorial') diff --git a/docs/tutorial/1-serialization.md b/docs/tutorial/1-serialization.md index 5b1ae6e8..5dcffcbd 100644 --- a/docs/tutorial/1-serialization.md +++ b/docs/tutorial/1-serialization.md @@ -340,9 +340,11 @@ You can install httpie using pip: Finally, we can get a list of all of the snippets: - http http://127.0.0.1:8000/snippets/ --body + http http://127.0.0.1:8000/snippets/ - [ + HTTP/1.1 200 OK + ... + [ { "id": 1, "title": "", @@ -367,7 +369,7 @@ Or we can get a particular snippet by referencing its id: HTTP/1.1 200 OK ... - { + { "id": 2, "title": "", "code": "print \"hello, world\"\n", diff --git a/docs/tutorial/2-requests-and-responses.md b/docs/tutorial/2-requests-and-responses.md index 08746cd7..49e96d03 100644 --- a/docs/tutorial/2-requests-and-responses.md +++ b/docs/tutorial/2-requests-and-responses.md @@ -127,7 +127,7 @@ Go ahead and test the API from the command line, as we did in [tutorial part 1][ We can get a list of all of the snippets, as before. - http http://127.0.0.1:8000/snippets/ + http http://127.0.0.1:8000/snippets/ HTTP/1.1 200 OK ... -- cgit v1.2.3 From f3ebac061e7b5a67afe1d9440876afa804d3995d Mon Sep 17 00:00:00 2001 From: phalt Date: Mon, 8 Dec 2014 15:47:49 +0000 Subject: one last tabs / spaces! --- docs/tutorial/1-serialization.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/tutorial') diff --git a/docs/tutorial/1-serialization.md b/docs/tutorial/1-serialization.md index 5dcffcbd..538b0d93 100644 --- a/docs/tutorial/1-serialization.md +++ b/docs/tutorial/1-serialization.md @@ -365,7 +365,7 @@ Finally, we can get a list of all of the snippets: Or we can get a particular snippet by referencing its id: - http http://127.0.0.1:8000/snippets/2/ + http http://127.0.0.1:8000/snippets/2/ HTTP/1.1 200 OK ... -- cgit v1.2.3 From 4e9ebb5fe9eee2ef6f21718d9becfb8e94bbbe98 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Mon, 8 Dec 2014 16:38:17 +0000 Subject: cd back to parent directory --- docs/tutorial/quickstart.md | 1 + 1 file changed, 1 insertion(+) (limited to 'docs/tutorial') diff --git a/docs/tutorial/quickstart.md b/docs/tutorial/quickstart.md index d0703381..f72fc7dd 100644 --- a/docs/tutorial/quickstart.md +++ b/docs/tutorial/quickstart.md @@ -22,6 +22,7 @@ Create a new Django project named `tutorial`, then start a new app called `quick django-admin.py startproject tutorial . cd tutorial django-admin.py startapp quickstart + cd .. Now sync your database for the first time: -- cgit v1.2.3 From 76956beab41cda7abdfb0aac714b35494f6ca3d5 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Tue, 9 Dec 2014 19:53:27 +0000 Subject: snippets relationship in tutorial should be read_only --- docs/tutorial/5-relationships-and-hyperlinked-apis.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/tutorial') diff --git a/docs/tutorial/5-relationships-and-hyperlinked-apis.md b/docs/tutorial/5-relationships-and-hyperlinked-apis.md index 58422929..57e3b6c5 100644 --- a/docs/tutorial/5-relationships-and-hyperlinked-apis.md +++ b/docs/tutorial/5-relationships-and-hyperlinked-apis.md @@ -85,7 +85,7 @@ We can easily re-write our existing serializers to use hyperlinking. In your `sn class UserSerializer(serializers.HyperlinkedModelSerializer): - snippets = serializers.HyperlinkedRelatedField(many=True, view_name='snippet-detail') + snippets = serializers.HyperlinkedRelatedField(many=True, view_name='snippet-detail', read_only=True) class Meta: model = User -- cgit v1.2.3 From 9b88b5db694b4cc68b87c87d967f912a47fa5817 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Thu, 11 Dec 2014 09:54:55 +0000 Subject: Field->ReadOnlyField in tutorial docs --- docs/tutorial/5-relationships-and-hyperlinked-apis.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/tutorial') diff --git a/docs/tutorial/5-relationships-and-hyperlinked-apis.md b/docs/tutorial/5-relationships-and-hyperlinked-apis.md index 57e3b6c5..c21efd7f 100644 --- a/docs/tutorial/5-relationships-and-hyperlinked-apis.md +++ b/docs/tutorial/5-relationships-and-hyperlinked-apis.md @@ -75,7 +75,7 @@ The `HyperlinkedModelSerializer` has the following differences from `ModelSerial We can easily re-write our existing serializers to use hyperlinking. In your `snippets/serializers.py` add: class SnippetSerializer(serializers.HyperlinkedModelSerializer): - owner = serializers.Field(source='owner.username') + owner = serializers.ReadOnlyField(source='owner.username') highlight = serializers.HyperlinkedIdentityField(view_name='snippet-highlight', format='html') class Meta: -- cgit v1.2.3