Skip to main content
 首页 » 编程设计

python之在 Django 中哪里放置自定义验证器

2024年10月01日44jiqing9006

我正在努力实现此处概述的解决方案:How to use custom password validators beside the django auth password validators?

答案非常有帮助,除了一个方面:我应该把验证器的代码放在哪里?!在 AUTH_PASSWORD_VALIDATORS 中,我看到了这一行:

'NAME': registration.validators.CustomPasswortValidator 

但是如何将 CustomPasswortValidator 方法放入 registration.validators 中? registration.validators 到底是什么?我在哪里可以找到它?

谢谢

请您参考如下方法:

下面一行:

'NAME': 'registration.validators.CustomPasswortValidator' 

意思是你需要一个注册应用,在那个应用里面有validators.py文件,在那个文件里面有一个方法 称为 CustomPasswortValidator。

因此,您可以通过提供自己的应用程序名称、文件名和方法名称来相应地工作。