in DRF (Django Rest Framework), he is given a token,
now next time through another view or through this login view how can the user make himself accessible with the token?
users need Just next time enter valid token for sign in
user needs to send this token in a headers (Authorization: Token your_token)
how? I am using swagger UI i can't
drf-yasg?
I am using 'rest_framework_swagger',
User need to pass this token in every request he made (in Authorization header)
https://django-rest-swagger.readthedocs.io/en/latest/settings/
yes but I got an error "username and password field must fill"
Do u have drf auth settings: REST_FRAMEWORK = { ... 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework.authentication.TokenAuthentication', 'rest_framework.authentication.BasicAuthentication' ) } ?
REST_FRAMEWORK = {'DEFAULT_SCHEMA_CLASS': ('rest_framework.schemas.coreapi.AutoSchema'), 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework.authentication.TokenAuthentication', ), 'DEFAULT_PARSER_CLASSES': ( 'rest_framework.parsers.FormParser', 'rest_framework.parsers.MultiPartParser', 'rest_framework.parsers.JSONParser', ), 'EXCEPTION_HANDLER': 'api.except_handler.custom_exception_handler', }
hmmm, so do u have SWAGGER_SETTINGS?
SWAGGER_SETTINGS = { "DEFAULT_GENERATOR_CLASS": "rest_framework.schemas.generators.BaseSchemaGenerator", 'VALIDATOR_URL': 'http://localhost:8189', "SHOW_REQUEST_HEADERS": True, 'SECURITY_DEFINITIONS': { 'api_key': { 'type': 'apiKey', 'in': 'header', 'name': 'Authorization' } }, }
does the error show up in all requests?
response=400 { "message": "non_field_errors: Unable to log in with provided credentials.\n", "code": "validation_error" }
here you passed Authorization named header
Обсуждают сегодня