我有一个带有名称、代码和密码的模型。我需要加密密码。另外,我不应该在密码字段中显示纯文本。 我提到了这个链接
Password field in Django model
但答案是旧的,需要知道现在的方法是什么。
我的模型如下
class Crew(models.Model):
crew_id = models.AutoField(primary_key=True)
crew_code = models.CharField(max_length=200, null=False, unique=True)
crew_name = models.CharField(max_length=200, null=False)
crew_password = models.CharField(max_length=200, null=False)
最佳答案
在你看来
from django.contrib.auth.hashers import make_password
crew_password = 'take the input if you are using form'
form = FormName(commit=False)
form.crew_password=make_password(crew_password)
form.save()
关于python - 如何加密django中的密码字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44450520/