我正在为我的 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 returnTrue
. 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
ifset_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/