我正在尝试使用Django REST framework创建一个用于登录我的Django网站的RESTful API。根据建议[{3}}我尝试使用here。
在我的settings.py
我添加了'rest_framework'
到INSTALLED_APPS
和
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',
),
}
我加了
url(r'^api-token-auth/', 'rest_framework_jwt.views.obtain_jwt_token'),
到我的url模式,如django-rest-framework-jwt doc中所指定的。
现在,当我尝试连接到我的网站时,出现以下错误:
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'
有人建议吗?
答案 0 :(得分:1)
检查您的DRF版本。 &#39; WRITE_ONLY&#39;在2.3.11版中添加了字段参数。见http://www.django-rest-framework.org/topics/release-notes