django tastypie自定义登录

时间:2012-05-10 10:56:23

标签: python django authentication tastypie

我现在对tastypie非常熟悉,它与授权和身份验证紧密结合。

是否有从另一个可以用于授权的位置的页面登录,而不是弹出美味的派对?

如果用户未使用浏览器而是使用原生应用,则会在移动设备上提出登录请求以登录此弹出窗口的方式。

它说的是401 Unauthorized

我试过的示例代码在

下面
class MyAuthentication(BasicAuthentication):
    def is_authenticated(self, request, **kwargs):
        from django.contrib.auth import authenticate
        #for now i tried static but still not working are return types correct     
        def is_authenticated(self, request, **kwargs):
            from django.contrib.auth import authenticate
            user = authenticate(username='admin', password='admin')

            if user is not None:
               if user.is_active:
                  return True
               else:
                 return self._unauthorized()
            else:
                return self._unauthorized()




class EntryResource(ModelResource):
    class Meta:
        queryset = Entry.objects.all()
        resource_name = 'entry'
        #authorization = Authorization()
        authorization = DjangoAuthorization()
        authentication = MyAuthentication()

    filtering = {
        'user': ALL_WITH_RELATIONS,
        'pub_date': ['exact', 'lt', 'lte', 'gte', 'gt'],
        }

1 个答案:

答案 0 :(得分:1)

关于django-tastypie官方文档,他们说永远不会使用授权进行生产部署,所以djangoauthorization必须有一个解决方法