Newtt
Newtt

Reputation: 6200

Using Django Rest Framework for only certain apps inside Django Application

I'm not sure if this is possible since an extensive search gave me nothing. Or I might be searching the wrong terms.

Now I have a few apps inside my Django application as follows:

--AppOne
--AppTwo
--ExtendedAdmin
manage.py

Now, AppOne and AppTwo use Django Rest Framework and its related Token Auth Mechanism. For the extendedAdmin, I'd like to use native Django Auth or even SessionAuth of DRF since I'm trying to add quite an extensive admin panel to the application. I've not been able to find a satisfactory way of customizing Django Rest Framework to work it's auth mechanisms only for certain applications. Is there a way to do this? If not, what should I be doing different?

Upvotes: 0

Views: 129

Answers (1)

brainless coder
brainless coder

Reputation: 6430

So far, I know you cannot. Because django rest framework intercepts the url and then performs its own logic of token validation. But there are solutions that you can use to keep both Session and Token Authentication.

I am using this for all my projects -

  1. I keep Session Authentication for all urls that will be accessed for normal browsing
  2. and I use api urls with django rest framework to be prefixed with /api for my api urls

For example -

The Session Based login is at http://<host>/account/login and TokenBased login is at http://<host>/api/account/login

The easiest way to make prefixed url for django rest framework is by using Routers - http://www.django-rest-framework.org/api-guide/routers/#defaultrouter

Example -

class UserViewSet(ModelViewSet): # just a sample view set
...

router = routers.SimpleRouter()
router.register(r'api/users', UserViewSet)

Upvotes: 1

Related Questions