mirror of
https://github.com/encode/django-rest-framework.git
synced 2026-03-03 11:31:21 +03:00
Update tutorial serialization page (#7945)
This commit is contained in:
parent
b659c2bf48
commit
40e77f0716
|
|
@ -15,7 +15,7 @@ Before we do anything else we'll create a new virtual environment, using [venv].
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python3 -m venv env
|
python3 -m venv env
|
||||||
source env/bin/activate
|
source env/bin/activate # On Windows use `env\Scripts\activate`
|
||||||
```
|
```
|
||||||
|
|
||||||
Now that we're inside a virtual environment, we can install our package requirements.
|
Now that we're inside a virtual environment, we can install our package requirements.
|
||||||
|
|
@ -217,6 +217,10 @@ Let's look at refactoring our serializer using the `ModelSerializer` class.
|
||||||
Open the file `snippets/serializers.py` again, and replace the `SnippetSerializer` class with the following.
|
Open the file `snippets/serializers.py` again, and replace the `SnippetSerializer` class with the following.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
from rest_framework import serializers
|
||||||
|
from snippets.models import Snippet
|
||||||
|
|
||||||
|
|
||||||
class SnippetSerializer(serializers.ModelSerializer):
|
class SnippetSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Snippet
|
model = Snippet
|
||||||
|
|
@ -362,9 +366,9 @@ Quit the server with CONTROL-C.
|
||||||
|
|
||||||
In another terminal window, we can test the server.
|
In another terminal window, we can test the server.
|
||||||
|
|
||||||
We can test our API using [curl][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 [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 using pip:
|
You can install HTTPie using pip:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install httpie
|
pip install httpie
|
||||||
|
|
@ -436,5 +440,5 @@ We'll see how we can start to improve things in [part 2 of the tutorial][tut-2].
|
||||||
[repo]: https://github.com/encode/rest-framework-tutorial
|
[repo]: https://github.com/encode/rest-framework-tutorial
|
||||||
[venv]: https://docs.python.org/3/library/venv.html
|
[venv]: https://docs.python.org/3/library/venv.html
|
||||||
[tut-2]: 2-requests-and-responses.md
|
[tut-2]: 2-requests-and-responses.md
|
||||||
[httpie]: https://github.com/httpie/httpie#installation
|
[HTTPie]: https://github.com/httpie/httpie#installation
|
||||||
[curl]: https://curl.haxx.se/
|
[curl]: https://curl.haxx.se/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user