django - 如何从 django 管理站点删除更改密码链接?

标签 django django-admin

我正在为我的 django Web 应用程序使用事件目录登录身份验证。因此无需在管理站点中更改密码链接。

我搜索了很多文章,但没有找到任何隐藏更改密码链接的内容。 那么向管理员隐藏更改密码链接的方法是什么?

最佳答案

您不需要覆盖管理模板。

如果user.has_usable_password()返回 False,然后 Django will not display change password URL for that user

user.has_usable_password()可以通过调用user.set_unusable_password()返回False

来自docs :

set_unusable_password()

Marks the user as having no password set. This isn’t the same as having a blank string for a password. check_password() for this user will never return True. Doesn’t save the User object.

You may need this if authentication for your application takes place against an existing external source such as an LDAP directory.

has_usable_password()

Returns False if set_unusable_password() has been called for this user.

Source code for condition filter in Django base admin template :

{% if user.has_usable_password %}
    <a href="{% url 'admin:password_change' %}">{% translate 'Change password' %}</a> 
{% endif %}

关于django - 如何从 django 管理站点删除更改密码链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62421279/

相关文章:

python - 如何访问 django 模板中的 django ManyToManyField

python - 如何在 Heroku Django 上安装 PyMuPDF

python - 在 Django 的管理中保存模型时执行检查

python - django 1.3 - 无法注册我的自定义 UserAdmin

python - django celery 和弦任务错误

python - 如何在不使用自动模型表单的情况下从 Django 的文本框中获取数据?

javascript - jQuery tablesorter 排序格式化货币

python - 在 Django 管理面板中无法添加和更改我的模型对象

python - django 中的自定义用户模型不允许在管理员中设置密码

django - 无法在 Admin Changeform 中反向匹配 url