我需要帮助覆盖Django Rest auth软件包中的用户注册字段

时间:2019-01-03 07:20:52

标签: django django-rest-framework django-rest-auth

我的自定义用户模型需要full_name emailpassword进行身份验证,而Django rest auth仅显示用户名电子邮件字段和两个密码字段。我可以通过声明自己的序列化程序来覆盖它,并且可以正常工作。但我收到此错误消息:

  

save()接受1个位置参数,但给出2个位置

{
    "username": "",
    "email": "",
    "password1": "",
    "password2": ""
}
  

save()接受1个位置参数,但给出2个位置

     

异常位置:perform_create第73行中的C:\ Users \ zeus \ Desktop \ alihub-back \ env \ lib \ site-packages \ rest_auth \ registration \ views.py

2 个答案:

答案 0 :(得分:0)

您可以尝试此link

如果问题没有解决。添加您尝试的内容

答案 1 :(得分:0)

i tried overiding the django rest auth views and serializer


so my views.py looks like this.

from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter
from rest_auth.registration.views import SocialLoginView
from rest_auth.registration.views import RegisterView


# from .permissions import IsOwnerOrReadOnly
from rest_framework import generics

from rest_framework.permissions import (

    AllowAny,
    )


from .serializers import (
    Registration,
    AccountDetailSerializer,
    )


from django.contrib.auth import get_user_model

User  = get_user_model()



class FacebookLogin(SocialLoginView):
    adapter_class = FacebookOAuth2Adapter

class RegisterAPIView(RegisterView):
    serializer_class   = Registration
    permission_classes = (AllowAny,)


    def get_queryset(self):
        User.objects.all()


but i still get the same error saying when i make a post request


save() takes 1 positional argument but 2 were given
Request Method: POST
Request URL:    http://127.0.0.1:8000/accounts/register/
Django Version: 2.0.8
Exception Type: TypeError
Exception Value:    
save() takes 1 positional argument but 2 were given
Exception Location: C:\Users\zeus\Desktop\alihub-back\env\lib\site-packages\rest_auth\registration\views.py in perform_create, line 73
Python Executable:  C:\Users\zeus\Desktop\alihub-back\env\Scripts\python.exe
Python Version: 3.6.0
Python Path:    
['C:\\Users\\zeus\\Desktop\\alihub-back\\src\\alihub',
 'C:\\Users\\zeus\\Desktop\\alihub-back\\env\\Scripts\\python36.zip',
 'C:\\Users\\zeus\\AppData\\Local\\Programs\\Python\\Python36\\DLLs',
 'C:\\Users\\zeus\\AppData\\Local\\Programs\\Python\\Python36\\lib',
 'C:\\Users\\zeus\\AppData\\Local\\Programs\\Python\\Python36',
 'C:\\Users\\zeus\\Desktop\\alihub-back\\env',`**strong text**`
 'C:\\Users\\zeus\\Desktop\\alihub-back\\env\\lib\\site-packages']
Server time:    Thu, 3 Jan 2019 13:50:04 +0000