# 12、Django解决扩展用户表时,后台ADMIN显示密码为明文的问题

### DJANGO解决扩展用户表时,后台ADMIN显示密码为明文的问题

大家都知道Django的AbstractUser吧，这里先不进行说明了，都知道，用的也很多。

这是我写的一个项目时用到的

![](/files/kmRhxrDUBdgPapmU7sJX)

在这里，我的用户表继承的就是AbstractUser，但是我在后台点击添加新用户的时候,密码是明文方式，很狗血！

解决方法：

```python
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.utils.translation import gettext_lazy
 
from teacher.models import UserProfile
 
 
@admin.register(UserProfile)
class UserProfileAdmin(UserAdmin):
    list_display = ['username', 'password']
    list_per_page = 10
 
    add_fieldsets = (
        (None, {u'fields': ('username', 'password1', 'password2')}),
        (gettext_lazy('User Information'), {'fields': ('TE_id', 'gender', 'phone', 'email')}),
    )
```

这个操作是完全解决了重写UserAdmin的密码明文问题

![](/files/OSWQygotM3nxrWyBYf6p)

亮点： 多了一个密码确认

密码： 加密

![](/files/qvvJ6nfSXkj3mosj3jAn)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://close.gitbook.io/yun-wei-bi-ji/python/django/12django-jie-jue-kuo-zhan-yong-hu-biao-shi-hou-tai-admin-xian-shi-mi-ma-wei-ming-wen-de-wen-ti.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
