Check your DRF's version. 'write_only' field parameter was added in version 2.3.11. See http://www.django-rest-framework.org/topics/release-notes
django-rest-framework-jwt: "__init__() got an unexpected keyword argument 'write_only'"
-
23-07-2023 - |
题
I'm trying to create a restful API to login to my Django site using Django REST framework. As recommended here I'm trying to use django-rest-framework-jwt.
In my settings.py
I added 'rest_framework'
to INSTALLED_APPS
and
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
),
}
and I added
url(r'^api-token-auth/', 'rest_framework_jwt.views.obtain_jwt_token'),
to my url patterns, as specified in the django-rest-framework-jwt doc.
Now when I try to connect to my site I get the following error:
File "/xxx/local/lib/python2.7/site-packages/rest_framework_jwt/views.py" in <module>
7. from .serializers import JSONWebTokenSerializer
File "/xxx/local/lib/python2.7/site-packages/rest_framework_jwt/serializers.py" in <module>
11. class JSONWebTokenSerializer(serializers.Serializer):
File "/xxx/local/lib/python2.7/site-packages/rest_framework_jwt/serializers.py" in JSONWebTokenSerializer
18. password = serializers.CharField(write_only=True)
File "/xxx/local/lib/python2.7/site-packages/rest_framework/fields.py" in __init__
453. super(CharField, self).__init__(*args, **kwargs)
Exception Type: TypeError at /
Exception Value: __init__() got an unexpected keyword argument 'write_only'
Any suggestion anyone?
解决方案
不隶属于 StackOverflow