Django rest framework pagination
<p>I am trying to add pagination into my project, couldn't find any clear documentation or tutorial.</p>

<p>I have a list of offices</p>

<p>models
Office.py</p>

<pre><code>class Office(Model):
    name = CharField(_("name"), default=None, max_length=255, null=True)
    email = EmailField(_("email"), default=None, max_length=255, null=True)
    description = TextField(_("description"), default=None, null=True)
</code></pre>

<p>Serializer</p>

<pre><code>class OfficeSerializer(ModelSerializer):
     id = IntegerField(read_only=True)
     name = CharField(read_only=True)
     email = URLField(read_only=True)
     description = CharField(read_only=True)

class Meta:
    model = Office
    fields = ("id", "name", "email", "description")
</code></pre>

<p>views.py</p>

<pre><code>@api_view(["GET"])
@permission_classes((AllowAny,))
def offices(request):
instance = Office.objects.filter()[:10]
serializer = OfficeSerializer(instance, many=True)

return Response(serializer.data)
</code></pre>

<p>Any help with returning Office list with pagination ?</p>

<p><a href="http://www.django-rest-framework.org/api-guide/pagination/" rel="nofollow">http://www.django-rest-framework.org/api-guide/pagination/</a></p>

<pre><code>GET https://api.example.org/accounts/?limit=100&amp;offset=400
</code></pre>

<p>Response:</p>

<pre><code>HTTP 200 OK
{
    "count": 1023
    "next": "https://api.example.org/accounts/?limit=100&amp;offset=500",
    "previous": "https://api.example.org/accounts/?limit=100&amp;offset=300",
    "results": [
       â¦
    ]
}
</code></pre>

<p>Example of <code>settings.py</code></p>

<pre><code>REST_FRAMEWORK = {
    'PAGE_SIZE': 10,
    'EXCEPTION_HANDLER': 'rest_framework_json_api.exceptions.exception_handler',
    'DEFAULT_PAGINATION_CLASS':
        'rest_framework_json_api.pagination.PageNumberPagination',
    'DEFAULT_PARSER_CLASSES': (
        'rest_framework_json_api.parsers.JSONParser',
        'rest_framework.parsers.FormParser',
        'rest_framework.parsers.MultiPartParser'
    ),
    'DEFAULT_RENDERER_CLASSES': (
        'rest_framework_json_api.renderers.JSONRenderer',
        'rest_framework.renderers.BrowsableAPIRenderer',
    )
}
</code></pre>

python django pagination django-rest-framework