现在如何在Django中处理每个对象的权限? [英] How to handle per object permission in Django nowadays?

查看:113
本文介绍了现在如何在Django中处理每个对象的权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要使用 django-guardian ,直到在官方文档:

I was about to use django-guardian until I came across the following in the official documentation:

https://docs.djangoproject.com/en/stable/topics/auth/customizing/#handling-authorization-in-custom-backends


不仅可以按对象类型设置权限,还可以按特定对象实例设置权限。通过使用ModelAdmin类提供的has_add_permission(),has_change_permission()和has_delete_permission()方法,可以为相同类型的不同对象实例自定义权限。

Permissions can be set not only per type of object, but also per specific object instance. By using the has_add_permission(), has_change_permission() and has_delete_permission() methods provided by the ModelAdmin class, it is possible to customize permissions for different object instances of the same type.

这是否意味着较新版本的Django不再需要django-guardian?

Does that mean django-guardian is no longer needed with newer versions of Django?

请说明。

推荐答案

实际上,在阅读文档时,我很高兴Django能够满足按对象权限检查的要求。开箱即用,尤其是在管理员中,这将是一个时间问题了解我如何激活它。

Indeed, while reading the docs, I got excited that Django would cater for "per object permissions checking" out of the box, especially in the admin, and that it would be a matter of time to understand how I could activate it.

但是,似乎并非总是如此

Django 毫无疑问地为这种实现提供了基础(API),但是这种实现有时需要良好的编码技巧和Django的理解

Django undoubtedly strives to provide the grounds (API) for such an implementation, but this implementation sometimes needs good coding skills and Django understanding.

由开发人员通过创建适合其需求的应用

这种矛盾的信息构成了我的网络爬虫的基础,该网络爬虫着重于寻找针对每个对象权限的解决方案。问题,以某种方式...有效地满足了我项目的需要或规模,当然还有我自己的编码技能和Django到目前为止的理解。

This contradicting information forms the base for my web crawling which focuses on finding a solution to the "per-object permissions" issue, somehow ... effectively for my project's needs or scale and of course my own coding skills and Django understanding up to now.

Django-guardian 似乎是最健壮,功能完善,功能完善的应用程序。

Django-guardian seems to be the most robust, full-fledged, full-blown application for this purpose.

还有其他更轻便的django应用程序可以满足生产中的特定需求也是稳定的。

There are also other more lightweight django applications that address specific needs which are production-stable, as well.

虽然在这个棘手的任务中努力维持生计,但我倾向于使用 django-rules ,因为它简单易行,并专注于我的需求。

While trying to make ends meet in this somehow tricky quest, I am leaning towards using django-rules for its simple and focused on my needs functioning.

这篇关于现在如何在Django中处理每个对象的权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆