8000 How to identify the action in ViewSets · Issue #7562 · encode/django-rest-framework · GitHub
[go: up one dir, main page]

Skip to content
How to identify the action in ViewSets #7562
Closed
@DeeKristo

Description

@DeeKristo

Hi All,

I am trying to restrict TokenAuthentication to some methods( in this case to my_method in the below snippet) in the ViewSets. Below is the snippet of code,

class MyViewSet(ViewSet):
    def get_authenticators(self):
        if self.action == 'my_method':
            return [TokenAuthentication()]
        return []

    def my_method(self, request, *args, **kwargs):
          < rest of logic goes here >

But I get the error saying , MyViewSet has no attribute action.

Am I doing it in a wrong way? or this is not available in the ViewSet.

Please let me know the correct way to achieve this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0