10. Configurando o REST_FRAMEWORK¶
LIB REST FRAMEWORK¶
Essa lib nos ajudará a trabalhar com o Django como API Rest.
Ativando a LIB REST FRAMEWORK¶
Edite o arquivo settings.py
e adicione abaixo de INSTALLED_APPS e CORS_ORIGIN_ALLOW_ALL o código:
REST_FRAMEWORK = { 'DEFAULT_PERMISSION_CLASSES': ( 'rest_framework.permissions.IsAuthenticated', # 'rest_framework.permissions.DjangoModelPermissions', # Habilitar se quiser fazer valer o controle de acesso do Admin do Django ), 'DEFAULT_FILTER_BACKENDS': ( 'django_filters.rest_framework.DjangoFilterBackend', ), 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework.authentication.TokenAuthentication', # 'rest_framework.authentication.SessionAuthentication', # Ativar em modo de desenvolvimento pra facilitar os testes da API com métodos GET ), 'DEFAULT_PARSER_CLASSES': ( 'rest_framework.parsers.JSONParser', ), 'COERCE_DECIMAL_TO_STRING': False, 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination', }