I am creating a restful API also with Django, like you. What I'm doing is applications that are independent, like your last example.
We have the βmainβ django application, where we have api_root in the views and a file called βapis_urls.pyβ, where we organize all the URLs from different applications.
We also have in this "main" application the file "apis_filters.py", where we have filters that can use any application with the API and "apis_permissions.py" to control permissions to use apis and import to another application.
So in the end we work like this:
project root | |-app1 / models.py .... views.py (app1 API), serializers.py, tests.py | |-app2 / models.py .... views.py (app2 API), serializers.py, tests.py | |-app3 / models.py .... views.py (app3 API), serializers.py, tests.py | \- core / views.py (api_root), apis_urls.py, apis_filters.py, apis_permissions.py
We conduct all tests in the corresponding application.
And having apis_urls.py, we can have all the API URLs, for example:
http://localhost/api/v1/example1 http://localhost/api/v1/example2
In the main urls.py we have:
url(r'^api/v1/', include('core.apis_urls', namespace='api')),
And in the main application, on the page "apis_urls.py":
urlpatterns = patterns( '', ####### Users Urls url(r'^users/$', users_views.UserListAPIView.as_view(), name='users-list-api'), url(r'^me/$', users_views.LoggedUserRetrieveUpdateAPIView.as_view(), name='logged-user-detail-api'), url(r'^users/(?P<username>[\ w.@ +-]+)/$', users_views.UserRetrieveAPIView.as_view(), name='users-detail-api'), ####### Comments Urls url(r'^comments/(?P<pk>[0-9]+)$', comments_api_views.CommentCreateAPIView.as_view(), name='comments-create-api'), )
I hope this help is how I found it more organized.