File: namespaces.rst

package info (click to toggle)
django-tastypie 0.13.3-1
  • links: PTS
  • area: main
  • in suites: buster, stretch
  • size: 1,768 kB
  • ctags: 2,614
  • sloc: python: 14,124; makefile: 83; sh: 52
file content (32 lines) | stat: -rw-r--r-- 1,041 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
.. _namespaces:

==========
Namespaces
==========

For various reasons you might want to deploy your API under a namespaced URL path. To support that tastypie includes ``NamespacedApi`` and ``NamespacedModelResource``.

A sample definition of your API in this case would be something like::

    from django.conf.urls import url, include
    from tastypie.api import NamespacedApi
    from my_application.api.resources import NamespacedUserResource

    api = NamespacedApi(api_name='v1', urlconf_namespace='special')
    api.register(NamespacedUserResource())

    urlpatterns = [
        url(r'^api/', include(api.urls, namespace='special')),
    ]

And your model resource::

    from django.contrib.auth.models import User
    from tastypie.resources import NamespacedModelResource
    from tastypie.authorization import Authorization

    class NamespacedUserResource(NamespacedModelResource):
        class Meta:
            resource_name = 'users'
            queryset = User.objects.all()
            authorization = Authorization()