我正在使用Djando rest_auth.registration.
我在urls.py中的相应条目是
url(r'^rest-auth/registration/', include('rest_auth.registration.urls'))
Run Code Online (Sandbox Code Playgroud)
我的身份验证类是rest_framework.authentication.TokenAuthentication
其余的API调用非常有效.
当我通过此API注册时,我得到以下响应.
{
"key": "3735f13cd69051579156f98ffda338a2d7a89bb5"
}
Run Code Online (Sandbox Code Playgroud)
我还想在响应中包含user_id字段.我该怎么做呢 我尝试从类RegisterView(CreateAPIView)扩展方法get_response_data:但无法这样做.有人可以建议实现这一目标的最佳做法.代码是理想的.谢谢.
我想使用rest_auth.registration提供的rest-auth/registration/url.我不想为此创建单独的新URL.
我的Settings.py如下
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'sdAPI.apps.SdapiConfig',
'rest_framework',
'rest_framework.authtoken',
'rest_auth',
'rest_framework_swagger',
'rest_auth.registration',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.facebook',
'allauth.socialaccount.providers.google',
'django_extensions',
]
# auth and allauth settings
LOGIN_REDIRECT_URL = '/'
SOCIALACCOUNT_QUERY_EMAIL = True
SOCIALACCOUNT_PROVIDERS = {
'facebook': {
'SCOPE': ['email', 'publish_stream'],
'METHOD': 'oauth2' # instead of 'oauth2'
}
}
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication', …Run Code Online (Sandbox Code Playgroud)