python - django tastypie 自定义登录

标签 python django authentication tastypie

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

无论如何,是否可以从另一个可用于授权的位置的页面登录,而不是弹出美味的馅饼授权?

当用户请求登录时,如果他们不使用浏览器而是使用 native 应用程序,则此弹出窗口将如何显示在他们的移动设备上。

它说 401 未经授权

下面是我试过的示例代码

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'],
        }

最佳答案

在 django-tastypie 官方文档上,他们说永远不要在生产部署中使用授权,所以必须有一个 djangoauthorization 的解决方法

关于python - django tastypie 自定义登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10532546/

相关文章:

python - 将文件写入不存在的目录

python - 使用 pandas,我如何有效地按组对大型 DataFrame 进行子采样?

django - 如何显示外键字段的名称而不是其 ID?

cakephp - 多个路由前缀+登录操作不起作用

python - 将小数输入转换为 int 时出错

python - Beautiful Soup - 获取包含字符串的参数属性

python - Docker 开发环境,pylint 无法导入错误

python - pycurl.POSTFIELDS 的问题

authentication - 使用 docker 设置 redis

JAVA - 使用 JAX-RS 和 JSON Web token 记住用户登录