mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 19:40:13 +03:00
Merge abb0241380
into ff4429fad4
This commit is contained in:
commit
103ae6a127
|
@ -84,7 +84,7 @@ We'll also need to create an initial migration for our snippet model, and sync t
|
|||
The first thing we need to get started on our Web API is to provide a way of serializing and deserializing the snippet instances into representations such as `json`. We can do this by declaring serializers that work very similar to Django's forms. Create a file in the `snippets` directory named `serializers.py` and add the following.
|
||||
|
||||
from rest_framework import serializers
|
||||
from snippets.models import Snippet, LANGUAGE_CHOICES, STYLE_CHOICES
|
||||
from .models import Snippet, LANGUAGE_CHOICES, STYLE_CHOICES
|
||||
|
||||
|
||||
class SnippetSerializer(serializers.Serializer):
|
||||
|
@ -220,8 +220,8 @@ Edit the `snippets/views.py` file, and add the following.
|
|||
from django.views.decorators.csrf import csrf_exempt
|
||||
from rest_framework.renderers import JSONRenderer
|
||||
from rest_framework.parsers import JSONParser
|
||||
from snippets.models import Snippet
|
||||
from snippets.serializers import SnippetSerializer
|
||||
from .models import Snippet
|
||||
from .serializers import SnippetSerializer
|
||||
|
||||
The root of our API is going to be a view that supports listing all the existing snippets, or creating a new snippet.
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user