Search code examples
djangorestdjango-rest-frameworkdjango-rest-auth

Django REST Framework: require login to view API


I am working through this series on the Django REST Framework and have a few videos left: https://www.youtube.com/playlist?list=PLEsfXFp6DpzTOcOVdZF-th7BS_GYGguAS

Unless I missed it somehow, I haven't seen anything on how to require login to view the API. I Googled such things as "Django REST require login", but didn't see anything other than creating authorization in general using Django REST API. I imagine there is a way to do it and would like to implement it because having a wide open API wouldn't work for my project.

Can someone point me in the right direction for setting login required for the API?


Solution

  • Got the answer in video 31. In project settings:

    REST_FRAMEWORK = {
        'DEFAULT_PERMISSION_CLASSES': (
            'rest_framework.permissions.IsAuthenticated',
        ),
    }