如何使用 django 禁用 HTML 视图?

问题描述

假设您正在使用 django Guardian 来实现某些对象级别的限制。

现在我有以下代码; 管理.py

class ControlAdmin(GuardedModelAdmin):
    prepopulated_fields = {"description": ("title",)}
    list_display = ('title','description','priority')
    search_fields = ('title','description')
    ordering = ('-title',)

现在我在数据库中选择了用户 maxdh 没有查看控件的权限,检查出来:

>>> control = Control.objects.first()
>>> checker = ObjectPermissionChecker(maxdh)
>>> checker.has_perm('change_control',control)
False
>>> checker.has_perm('view_control',control)
False

但是,当我转到为控件呈现表格的 html 时,我仍然可以看到表格:

enter image description here

html:

    <div class="card-body">
        <div class="card-body">
            {% load django_tables2 %}
            {% render_table controls %}

我缺少什么?

我阅读了文档但无法识别

请帮忙!

解决方法

尝试了以下方法:

module.exports.run = async (bot,message,args) => {
    const channel = message.guild.channels.cache.get('458524389936201730');
    channel.send('test');
};

module.exports.help = {
  name: "xxx"
};

然而导致

    {% load guardian_tags %}
    {% get_obj_perms request.user for Control as "control_perms" %}
    {% if "view_control" in control_perms %}
    <div class="card-body">
        <div class="card-body">
            {% load django_tables2 %}
            {% render_table controls %}
        </div>
    {% endif %}