1
- import coreapi
2
- import coreschema
3
1
from rest_framework import parsers , renderers
4
2
from rest_framework .authtoken .models import Token
5
3
from rest_framework .authtoken .serializers import AuthTokenSerializer
4
+ from rest_framework .compat import coreapi , coreschema
6
5
from rest_framework .response import Response
7
6
from rest_framework .schemas import ManualSchema
8
7
from rest_framework .views import APIView
@@ -14,29 +13,30 @@ class ObtainAuthToken(APIView):
14
13
parser_classes = (parsers .FormParser , parsers .MultiPartParser , parsers .JSONParser ,)
15
14
renderer_classes = (renderers .JSONRenderer ,)
16
15
serializer_class = AuthTokenSerializer
17
- schema = ManualSchema (
18
- fields = [
19
- coreapi .Field (
20
- name = "username" ,
21
- required = True ,
22
- location = 'form' ,
23
- schema = coreschema .String (
24
- title = "Username" ,
25
- description = "Valid username for authentication" ,
16
+ if coreapi is not None and coreschema is not None :
17
+ schema = ManualSchema (
18
+ fields = [
19
+ coreapi .Field (
20
+ name = "username" ,
21
+ required = True ,
22
+ location = 'form' ,
23
+ schema = coreschema .String (
24
+ title = "Username" ,
25
+ description = "Valid username for authentication" ,
26
+ ),
26
27
),
27
- ),
28
- coreapi . Field (
29
- name = "password" ,
30
- required = True ,
31
- location = 'form' ,
32
- schema = coreschema . String (
33
- title = "Password " ,
34
- description = "Valid password for authentication" ,
28
+ coreapi . Field (
29
+ name = "password" ,
30
+ required = True ,
31
+ location = 'form' ,
32
+ schema = coreschema . String (
33
+ title = "Password" ,
34
+ description = "Valid password for authentication " ,
35
+ ) ,
35
36
),
36
- ),
37
- ],
38
- encoding = "application/json" ,
39
- )
37
+ ],
38
+ encoding = "application/json" ,
39
+ )
40
40
41
41
def post (self , request , * args , ** kwargs ):
42
42
serializer = self .serializer_class (data = request .data ,
0 commit comments