Settings.py
REST_FRAMEWORK = {'DEFAULT_AUTHENTICATION_CLASSES' :( 'rest_framework.authentication.BasicAuthentication',), 'DEFAULT_PERMISSION_CLASSES'Iut.uthected_services.Int_AutБезисов_ответа_данных_произведения_даваемых_переключений',)}
models.py
from django.db import models
class Emp(models.Model):
eid = models.IntegerField()
ename = models.CharField(max_length=30)
sal = models.IntegerField()
def __str__(self):
return self.ename
admin.py
from django.contrib import admin
from .models import Emp
class AdminEmp(admin.ModelAdmin):
list_display = ['eid','ename','sal']
admin.site.register(Emp,AdminEmp)
serializers.py
from .models import Emp
from rest_framework import serializers
class EmpSerializer(serializers.ModelSerializer):
class Meta:
model = Emp
fields = ('eid','ename','sal')
views.py
from .serializers import EmpSerializer
from .models import Emp
from rest_framework import viewsets
from rest_framework.authentication import BaseAuthentication
from rest_framework.permissions import IsAuthenticated
class EmpViewSet2(viewsets.ModelViewSet):
authentication_classes = (BaseAuthentication,)
permission_classes = (IsAuthenticated,)
queryset = Emp.objects.all()
serializer_class = EmpSerializer
уровень приложения urls.py
from django.conf.urls import url,include
from .views import EmpViewSet2
from rest_framework.routers import DefaultRouter
router = DefaultRouter()
router.register('emp_viewset',EmpViewSet2,base_name='emp_viewset2')
urlpatterns = [
url(r'',include(router.urls)) ]
Уровень проекта urls.py
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path('admin/', admin.site.urls),
path('api/', include('Basic_Authentication_App.urls'))
]
Окно имени пользователя и пароля
Окно Django Rest Framework , но когда я нажимаю на эту ссылку "emp_viewset": "http://127.0.0.1:3499/api/emp_viewset/"
это выглядит так: NotImplementedError at / api / emp_viewset / .authenticate () должен быть переопределен.