我现在对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'],
}
答案 0 :(得分:1)