私はDjangoを学んでいます。ログインAPIと登録API用の残りのAPIを作成していましたが、機能していましたが、突然ログインAPIが機能しません
authenticate(username=username, password=password)
登録APIが正常に機能している間は、常に何も返されません。以下はログイン用のコードです
@api_view(['POST'])
def login(requset):
"""
This api for user login
---
parameters:
- name: username
description: username for login
required: true
type: string
paramType: form
- name: password
required: true
type: string
paramType: form
consumes:
- application/json
- application/xml
produces:
- application/json
- application/xml
"""
username = requset.data.get('username')
print(username)
password = requset.data.get('password')
print(password)
user = authenticate(username=username, password=password)
if user is not None:
response_data = {}
response_data['result'] = 'success'
response_data['message'] = 'Login successful'
# response_data['auth_token'] = auth_token
return HttpResponse(json.dumps(response_data),
content_type="application/json")
else:
response_data = {}
response_data['result'] = 'error'
response_data['message'] = 'Login Unsuccessful'
return HttpResponse(json.dumps(response_data),
content_type="application/json")
これは登録用のコードです
class Register(generics.CreateAPIView):
"""
Your docs
---
type:
username:
required: true
type: string
password:
required: true
type: url
email:
required: true
type: string
serializer: .serializers.UserSerializer
omit_serializer: false
parameters_strategy: merge
omit_parameters:
- path
parameters:
- name: username
description: Username for registration purpose
required: true
type: string
paramType: form
- name: password
description: * password for registration purpose
required: true
type: string
paramType: form
- name: email
description: * email for registration purpose
required: true
type: string
paramType: form
responseMessages:
- code: 401
message: Not authenticated
consumes:
- application/json
- application/xml
produces:
- application/json
- application/xml
"""
#first define query set
queryset = User.objects.all()
#define model
model = User
#define serializer
serializer_class = UserSerializer
ユーザーシリアライザーのコード
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ('id','username','email','password','is_active')
私はいつも応答を下回ります
{
"message": "Login Unsuccessful",
"result": "error"
}
以前は適切に来ていましたが。どんな助けでも大歓迎です。