我正在使用dj-rest-auth (https://dj-rest-auth.readthedocs.io/en/latest/),并尝试实现一个自定义注册表单。当我尝试注册新用户时,我只有基础表格。
我曾经看过旧版本的(https://django-rest-auth.readthedocs.io/en/latest/),如果您使用password1和password2,则无需重复输入所有代码。
serializers.py
serializers.py
from rest_framework import serializers
from dj_rest_auth.registration.serializers import RegisterSerializer
class CustomRegisterSerializer(RegisterSerializer):
first_name = serializers.CharField()
last_name = serializers.CharField()
def get_cleaned_data(self):
super(CustomRegisterSerializer, self).get_cleaned_data()
return {
'username': self.validated_data.get('username', ''),
'password1': self.validated_data.get('password1', ''),
'password2': self.validated_data.get('password2', ''),
'email': self.validated_data.get('email', ''),
'first_name': self.validated_data.get('first_name', ''),
'last_name': self.validated_data.get('last_name', '')
}
settings.py
REST_AUTH_SERIALIZERS = {
'REGISTER_SERIALIZER': 'accounts.serializers.CustomRegisterSerializer',
}
REST_AUTH = {
,如此处所述:https://dj-rest-auth.readthedocs.io/en/latest/configuration.html - art_hq