【问题标题】:How to create views where superuser can view and edit other user's passwords in Django?如何在 Django 中创建超级用户可以查看和编辑其他用户密码的视图?
【发布时间】:2018-05-05 06:38:22
【问题描述】:

我正在创建一个控制面板,超级用户可以在其中查看所有用户及其信息的表格。我想将用户密码添加到列中,并添加指向编辑表单的链接以更改密码。

【问题讨论】:

  • 为什么不使用 django admin,你讨厌这种风格吗? CHANGE IT!
  • Django 管理员允许重置密码,但它不显示它:它只是一个哈希。
  • Django 只存储哈希。无法显示原始密码。

标签: django


【解决方案1】:

假设你有list_passwords查看你发送的超级用户可以查看密码

from django.views.decorators.http import require_http_methods

@require_http_methods(['GET'])
def list_password(request):
    if not request.user.is_superuser:
        # return with error
    else:
        # return data 

另一个更新密码的视图

@require_http_methods(['PATCH'])
def update_password(request):
   if not request.user.is_superuser:
       # return with error
   else:
       # update user password 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-03
    • 1970-01-01
    • 1970-01-01
    • 2022-12-24
    • 2021-10-13
    • 1970-01-01
    • 2021-10-27
    相关资源
    最近更新 更多