【问题标题】:How do I set authentication_classes on custom route?如何在自定义路由上设置 authentication_classes?
【发布时间】:2015-01-22 17:17:48
【问题描述】:

我的视图集上有一个特定的自定义路由,它基本上是对细节对象的一个​​操作,在 url 中有一个额外的参数(例如,r'^{prefix}/{lookup}/sub_items/$')。我想为此路由指定与视图集的其余部分不同的 authentication_class。我在哪里可以指定?我看到有 @list_route 和 @detail_route 析构函数可以用来指定,但是自定义路由呢?

谢谢。

【问题讨论】:

    标签: django-rest-framework


    【解决方案1】:

    我想通了。路线应该设置:

    initkwargs={'authentication_classes': (authentication.MyCustomAuthenticationForThisRoute,)}

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-26
      • 1970-01-01
      • 1970-01-01
      • 2016-04-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多