{"id":392667,"date":"2024-06-29T10:32:38","date_gmt":"2024-06-29T10:32:38","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=392667"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-06-29T10:32:38","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=392667","title":{"rendered":"<span>403, 404 \u0438\u043b\u0438 405. \u0420\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0441\u043e \u0441\u0442\u0430\u0442\u0443\u0441\u0430\u043c\u0438 \u0432\u043e ViewSet\u2019\u0430\u0445 DRF<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b3d\/fdb\/05b\/b3dfdb05b9f11cdb213c22ceebad39da.png\" alt=\"\u042d\u0442\u043e \u044f \u0443\u0435\u0437\u0436\u0430\u044e \u0432 \u0437\u0430\u043a\u0430\u0442, \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u043f\u044b\u0442\u043e\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c REST \u043d\u0430 Django.\" title=\"\u042d\u0442\u043e \u044f \u0443\u0435\u0437\u0436\u0430\u044e \u0432 \u0437\u0430\u043a\u0430\u0442, \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u043f\u044b\u0442\u043e\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c REST \u043d\u0430 Django.\" width=\"1920\" height=\"1080\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b3d\/fdb\/05b\/b3dfdb05b9f11cdb213c22ceebad39da.png\"\/><\/p>\n<div><figcaption>\u042d\u0442\u043e \u044f \u0443\u0435\u0437\u0436\u0430\u044e \u0432 \u0437\u0430\u043a\u0430\u0442, \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u043f\u044b\u0442\u043e\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c REST \u043d\u0430 Django.<\/figcaption><\/div>\n<\/figure>\n<p>\u0418\u0434\u0435\u044f \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0439 REST \u043d\u0430 Django \u2013 \u0443\u0442\u043e\u043f\u0438\u044f, \u043d\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0435 \u0438 \u043d\u0435\u0442 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e, \u0447\u0442\u043e \u043e\u0431 \u044d\u0442\u043e\u043c \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c. \u041d\u0438\u0436\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u043f\u0440\u043e \u0442\u043e, \u043a\u0430\u043a \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 <code>ViewSet<\/code> \u043e\u0442 <code>GenericViewSet<\/code> \u0438 \u043f\u0430\u0440\u044b \u043c\u0438\u043a\u0441\u0438\u043d\u043e\u0432 \u0432 DRF, \u043f\u043e\u043a\u0440\u044b\u043b\u0438 \u044d\u0442\u043e \u0432\u0441\u0435 \u0442\u0435\u0441\u0442\u0430\u043c\u0438 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043c\u0435\u0441\u0442\u0430\u043c\u0438 \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0435, \u043d\u043e \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043a\u043e\u0434\u044b \u043e\u0442\u0432\u0435\u0442\u043e\u0432.<\/p>\n<p>\u0422\u0435\u043a\u0441\u0442 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u0435\u043d \u043d\u043e\u0432\u0438\u0447\u043a\u0430\u043c (\u0438\u043b\u0438 \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0448\u0430\u0440\u0435\u043d\u043d\u044b\u043c) \u0432 Django, \u0434\u0430\u0431\u044b \u0443\u043b\u043e\u0436\u0438\u0442\u044c \u0432 \u0433\u043e\u043b\u043e\u0432\u0435 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 url\u2019\u043e\u0432 \u0438 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 permission-\u043a\u043b\u0430\u0441\u0441\u043e\u0432. \u041d\u0443 \u0430 \u0431\u044b\u0432\u0430\u043b\u044b\u0435 \u0441\u043a\u0430\u0436\u0443\u0442, \u0447\u0442\u043e \u0432\u0441\u0435 \u044d\u0442\u043e \u0431\u0430\u043b\u043e\u0432\u0441\u0442\u0432\u043e \u0438 \u043d\u0430\u0434\u043e \u0431\u044b\u043b\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>GenericApiView<\/code>.<\/p>\n<h3>\u041c\u0430\u0440\u0448\u0440\u0443\u0442 \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d. 404 \u0438\u043b\u0438 405?<\/h3>\n<p>\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u0432\u0435\u0431 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f &#8212; CRUD \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0420\u0435\u0448\u0438\u043b\u0438 \u043c\u044b \u043f\u043e\u0447\u0435\u043c\u0443-\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u044d\u0442\u0438\u0445 \u0446\u0435\u043b\u0435\u0439 <code>ViewSet<\/code>, \u043d\u043e \u0440\u0443\u0447\u043a\u0438 \u043d\u0443\u0436\u043d\u044b \u0431\u044b\u043b\u0438 \u043d\u0435 \u0432\u0441\u0435 \u0438 \u0447\u0442\u043e\u0431\u044b \u043b\u0438\u0448\u043d\u0435\u0435 \u043d\u0435 \u0432\u044b\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u0442\u044c, \u0432\u0437\u044f\u043b\u0438 <code>GenericViewSet<\/code> \u0438 \u043d\u0443\u0436\u043d\u044b\u0439 <code>Mixin<\/code>. <\/p>\n<details class=\"spoiler\">\n<summary>\u0417\u0430\u0447\u0435\u043c \u0442\u0430\u043a \u0441\u043b\u043e\u0436\u043d\u043e?<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0414\u0430, \u0432\u044b\u0431\u043e\u0440 \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0439, \u043d\u043e \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u0443\u043c\u0430\u043b\u0447\u0438\u0432\u0430\u0435\u0442 \u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u0445 \u0442\u0430\u043a\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u0447\u0442\u043e \u0438\u043c\u0435\u0435\u043c \u0447\u0442\u043e \u0438\u043c\u0435\u0435\u043c.<\/p>\n<\/div>\n<\/details>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u0443:<\/p>\n<pre><code class=\"python\">class UsersViewSet(mixins.UpdateModelMixin, GenericViewSet):     pass <\/code><\/pre>\n<p>\u0412\u0441\u0435, \u0447\u0442\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0430\u0441 \u043f\u043e\u043a\u0430 \u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043f\u0443\u0441\u0442\u0438\u043c \u044d\u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442.\u00a0<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b\u0438 \u0432\u043e\u0442 \u0442\u0430\u043a\u0438\u0435 \u043f\u0443\u0442\u0438:<\/p>\n<pre><code class=\"python\">router = SimpleRouter() router.register(\"users\", UsersViewSet, basename=\"users\")<\/code><\/pre>\n<p>\u0418 \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043d\u0430\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0447\u0442\u043e \u043b\u0438\u0448\u043d\u0438\u0435 \u0440\u0443\u0447\u043a\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b (\u0447\u0442\u043e\u0431\u044b \u0432\u0441\u044f\u043a\u0438\u0435 \u0442\u0430\u043c \u043c\u0438\u043c\u043e\u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043b\u044b \u0438\u0445 \u043d\u0435 \u0442\u0440\u043e\u0433\u0430\u043b\u0438) \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 \u044d\u0442\u043e \u0432\u0441\u0435 \u0434\u0435\u043b\u043e \u0442\u0435\u0441\u0442\u043e\u0432.<\/p>\n<pre><code class=\"python\">def test_list_user(auth_free_client_and_user):    client, user = auth_free_client_and_user      response = client.get(\"\/api\/users\/\")    assert response.status_code == 404, response.json()   def test_delete_user(auth_free_client_and_user):    client, user = auth_free_client_and_user      response = client.delete(f\"\/api\/users\/{user.id}\/\")    assert response.status_code == 404, response.json()<\/code><\/pre>\n<p><strong>\u0412\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0432\u043e\u043f\u0440\u043e\u0441:<\/strong> \u0431\u0443\u0434\u0435\u0442 \u043b\u0438 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c?\u00a0<\/p>\n<details class=\"spoiler\">\n<summary>\u041e\u0442\u0432\u0435\u0442 \u0443\u0431\u0438\u043b<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041d\u0435\u0442<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/8e6\/72c\/b5b\/8e672cb5bd274a76235334a7f0274009.png\" width=\"1600\" height=\"469\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8e6\/72c\/b5b\/8e672cb5bd274a76235334a7f0274009.png\"\/><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0427\u0435\u043b\u043e\u0432\u0435\u043a\u0443, \u043d\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u0437\u043d\u0430\u043a\u043e\u043c\u043e\u043c\u0443 \u0441 DRF \u043f\u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043d\u0430\u0448\u0438 \u0442\u0435\u0441\u0442\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u041d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043e\u043d\u0438 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442.\u00a0\u0410 \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u043f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u0432 \u043a\u043b\u0430\u0441\u0441 <code>Router<\/code> \u0438\u0437 DRF, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u044d\u0442\u0443 \u043e\u0448\u0438\u0431\u043a\u0443. <\/p>\n<h4>\u041a\u0430\u043a \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043c\u0430\u0440\u0448\u0440\u0443\u0442<\/h4>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 DRF, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u044e\u0442 \u043f\u043e\u0447\u0435\u043c\u0443 \u0442\u0435\u0441\u0442\u044b \u043f\u0430\u0434\u0430\u044e\u0442 \u0438 \u0432\u044b\u0434\u0430\u044e\u0442 \u043d\u0435 \u0442\u0435 http-\u0441\u0442\u0430\u0442\u0443\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0436\u0438\u0434\u0430\u043b\u0438\u0441\u044c. \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0435\u043d \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u043b\u0438\u0441\u0442\u0430\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u0434\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430.\u00a0<\/p>\n<p>\u041f\u0440\u0438\u0447\u0438\u043d\u0430 AssertionError \u0432 \u0442\u0435\u0441\u0442\u0435 \u0432 \u0442\u043e\u043c, \u043a\u0430\u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 <code>Router<\/code>. \u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 <code>SimpleRouter<\/code> \u0438\u0437 DRF \u0443\u0432\u0438\u0434\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 (<a href=\"https:\/\/github.com\/encode\/django-rest-framework\/blob\/master\/rest_framework\/routers.py#L93\" rel=\"noopener noreferrer nofollow\">\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0430<\/a>):<\/p>\n<pre><code class=\"python\">class SimpleRouter(BaseRouter):      routes = [        # List route.        Route(            url=r'^{prefix}{trailing_slash}$',            mapping={                'get': 'list',                'post': 'create'            },            name='{basename}-list',            detail=False,            initkwargs={'suffix': 'List'}        ),        # Dynamically generated list routes. Generated using        # @action(detail=False) decorator on methods of the viewset.        DynamicRoute(            url=r'^{prefix}\/{url_path}{trailing_slash}$',            name='{basename}-{url_name}',            detail=False,            initkwargs={}        ),        # Detail route.        Route(            url=r'^{prefix}\/{lookup}{trailing_slash}$',            mapping={                'get': 'retrieve',                'put': 'update',                'patch': 'partial_update',                'delete': 'destroy'            },            name='{basename}-detail',            detail=True,            initkwargs={'suffix': 'Instance'}        ),        # Dynamically generated detail routes. Generated using        # @action(detail=True) decorator on methods of the viewset.        DynamicRoute(            url=r'^{prefix}\/{lookup}\/{url_path}{trailing_slash}$',            name='{basename}-{url_name}',            detail=True,            initkwargs={}        ),    ] <\/code><\/pre>\n<p>\u0427\u0442\u043e \u0432\u0430\u0436\u043d\u043e \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c:\u00a0<\/p>\n<ul>\n<li>\n<p>\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u0437 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 <code>Route<\/code><\/p>\n<\/li>\n<li>\n<p>\u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0435 \u0437\u0430\u0434\u0430\u044e\u0442\u0441\u044f:<\/p>\n<ul>\n<li>\n<p><code>url<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u00a0<\/p>\n<\/li>\n<li>\n<p><code>mapping<\/code> &#8212; \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u0437 http-\u043c\u0435\u0442\u043e\u0434\u0430 \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u043d\u0430\u0448\u0435\u0433\u043e <code>ViewSet<\/code>\u00a0<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u0415\u0449\u0435 \u043d\u0430\u043c \u0432\u0430\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432 \u044d\u0442\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 (<a href=\"https:\/\/github.com\/encode\/django-rest-framework\/blob\/master\/rest_framework\/routers.py#L226\" rel=\"noopener noreferrer nofollow\">\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0430<\/a>):\u00a0<\/p>\n<pre><code class=\"python\">def get_method_map(self, viewset, method_map):    \"\"\"    Given a viewset, and a mapping of http methods to actions,    return a new mapping which only includes any mappings that    are actually implemented by the viewset.    \"\"\"    bound_methods = {}    for method, action in method_map.items():        if hasattr(viewset, action):            bound_methods[method] = action    return bound_methods <\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c <code>method_map<\/code> \u044d\u0442\u043e mapping \u0438\u0437 \u043d\u0430\u0448\u0438\u0445 <code>Route<\/code>.\u00a0<\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0434\u043b\u044f:<\/p>\n<pre><code class=\"python\">url=r'^{prefix}{trailing_slash}$' - \u043d\u0435 \u0432\u0435\u0440\u043d\u0435\u0442\u0441\u044f \u043d\u0438\u0447\u0435\u0433\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0438\u0437 mapping \u043d\u0435\u0442 \u0432 \u043d\u0430\u0448\u0435\u043c ViewSet url=r'^{prefix}\/{lookup}{trailing_slash}$' - \u0432\u0435\u0440\u043d\u0435\u0442\u0441\u044f \u0441\u043b\u043e\u0432\u0430\u0440\u044c {\u201cput\u201d: \u201cupdate\u201d} <\/code><\/pre>\n<p>\u041d\u0443 \u0438 \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0435\u0441\u043b\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0432 <code>get_url<\/code> \u0432\u0441\u0435 \u0442\u043e\u0433\u043e \u0436\u0435 <code>SimpleRouter<\/code>, \u0442\u043e \u0443\u0432\u0438\u0434\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 (<a href=\"https:\/\/github.com\/encode\/django-rest-framework\/blob\/master\/rest_framework\/routers.py#L278\" rel=\"noopener noreferrer nofollow\">\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0430<\/a>):<\/p>\n<pre><code class=\"python\"># Only actions which actually exist on the viewset will be bound mapping = self.get_method_map(viewset, route.mapping) if not mapping:    continue <\/code><\/pre>\n<h2>\u0418\u0442\u043e\u0433\u043e<\/h2>\n<p>\u0418\u0437-\u0437\u0430 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0442 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043e\u0442 <code>UpdateModelMixin<\/code> <code>SimpleRouter<\/code> \u0441\u043e\u0437\u0434\u0430\u043b \u043d\u0430\u043c \u043c\u0430\u0440\u0448\u0440\u0443\u0442 \u0432\u0438\u0434\u0430 <code>\/users\/:id<\/code>, \u043d\u043e \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u043b \u0442\u0430\u043c \u0442\u043e\u043b\u044c\u043a\u043e http-\u043c\u0435\u0442\u043e\u0434\u044b PUT \u0438 PATCH. \u041d\u043e \u0434\u043b\u044f DELETE \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u043e\u0442 \u0436\u0435 \u043c\u0430\u0440\u0448\u0440\u0443\u0442, \u043d\u043e \u0434\u0440\u0443\u0433\u043e\u0439 \u043c\u0435\u0442\u043e\u0434.\u00a0<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0435\u0440\u0432\u044b\u0439 \u0442\u0435\u0441\u0442 \u043d\u0430 <code>list<\/code> \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0443\u0447\u0430\u0442\u044c\u0441\u044f \u043d\u0430 <code>\/users<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u043b\u0438 \u0438 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0432 \u043e\u0442\u0432\u0435\u0442 404, \u0430 \u0432\u043e\u0442 \u0432\u0442\u043e\u0440\u043e\u0439 \u0442\u0435\u0441\u0442 \u043d\u0430 <code>delete<\/code> \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0443\u0447\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442 \u0441 \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442 \u0432 \u043e\u0442\u0432\u0435\u0442 405.<\/p>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0435 \u0442\u0435\u0441\u0442\u044b \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">def test_list_user(auth_free_client_and_user):    client, user = auth_free_client_and_user      response = client.get(\"\/api\/users\/\")    assert response.status_code == 404, response.json()   def test_delete_user(auth_free_client_and_user):    client, user = auth_free_client_and_user      response = client.delete(f\"\/api\/users\/{user.id}\/\")    assert response.status_code == 405, response.json()<\/code><\/pre>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e, Django!<\/p>\n<h3>403 \u0438\u043b\u0438 404. \u041f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u201c\u0441\u0432\u043e\u0438\u201d \u0437\u0430\u043f\u0438\u0441\u0438.<\/h3>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b: \u043d\u0443 \u043b\u0430\u0434\u043d\u043e, \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u043d\u043e \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u043b\u043e\u0433\u0438\u0447\u043d\u043e. \u0417\u0430\u043f\u043e\u043c\u043d\u0438\u043b\u0438 \u0438 \u0440\u0430\u0437\u043e\u0448\u043b\u0438\u0441\u044c. \u041d\u043e \u043d\u0430 \u044d\u0442\u043e\u043c \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u043d\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0430\u0441\u044c \u0438 \u043d\u0430 \u0442\u043e\u043c \u0436\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043c\u044b \u0441\u043d\u043e\u0432\u0430 \u043d\u0430\u0442\u043a\u043d\u0443\u043b\u0438\u0441\u044c \u043d\u0430 \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u0442\u0430\u0442\u0443\u0441\u044b (\u0445\u043e\u0442\u044c \u0438 \u0432\u043f\u043e\u043b\u043d\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u043c\u044b\u0435).<\/p>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d <code>ViewSet<\/code> \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0435\u043c\u0443 <code>permission<\/code>-\u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0442\u043e, \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u043c\u043d\u0435 \u043a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u044d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c.<\/p>\n<pre><code class=\"python\">class PostViewSet(ModelViewSet):    permission_classes = [IsAuthenticated, UserPermission] <\/code><\/pre>\n<p><code>Permission<\/code>-\u043a\u043b\u0430\u0441\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0442\u0434\u0430\u0442\u044c \u043d\u0430\u043c 403 \u043a\u043e\u0434 \u043e\u0448\u0438\u0431\u043a\u0438 &#8212; \u0434\u043e\u0441\u0442\u0443\u043f \u0437\u0430\u043f\u0440\u0435\u0449\u0435\u043d &#8212; \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u0447\u0443\u0436\u043e\u0439 \u043f\u043e\u0441\u0442.<\/p>\n<pre><code class=\"python\">class UserPermission(permissions.BasePermission):      def has_object_permission(self, request, view, obj):        \"\"\"\u0414\u043e\u0441\u0442\u0443\u043f \u043a \u043e\u0431\u044a\u0435\u043a\u0442\u0443.\"\"\"        if view.action in {\"retrieve\", \"update\", \"partial_update\"}:            return obj.user_id == request.user.id        return False <\/code><\/pre>\n<p>\u041d\u043e \u0442\u0430\u043a\u0436\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u0442\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c <code>queryset<\/code> &#8212; \u0437\u0430\u043f\u0440\u043e\u0441, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0434\u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u0434\u043e\u0441\u0442\u0430\u0432\u0430\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u0441 \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u043c \u043f\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e.<\/p>\n<pre><code class=\"python\">class PostViewSet(ModelViewSet):    permission_classes = [IsAuthenticated, UserPermission]      def get_queryset(self):        \"\"\"\u0424\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c \u043f\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e.\"\"\"        return Post.objects.filter(user=self.request.user) <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0432\u043e \u0432\u0441\u0435\u0445 \u043c\u0435\u0442\u043e\u0434\u0430\u0445 \u043d\u0430\u0448\u0435\u0433\u043e ViewSet \u0431\u0443\u0434\u0443\u0442 \u0441\u0440\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043b\u0438\u0448\u043d\u0435\u0433\u043e. \u041d\u043e \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442 \u0435\u0441\u043b\u0438 \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0447\u0443\u0436\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e?\u00a0<\/p>\n<p>\u041e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e 403. \u0418 \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043a\u0440\u044b\u0442\u044c \u044d\u0442\u043e \u0442\u0435\u0441\u0442\u043e\u043c, \u0442\u043e \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043a\u0430\u043a-\u0442\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">def test_update_another_user(auth_client_and_user, another_user):    client, user = auth_client_and_user      response = client.patch(        f\"\/api\/posts\/{another_user.id}\/\",        {            \"text\": \"new amazing text\",        },    )      assert response.status_code == 403, response.json()<\/code><\/pre>\n<p>\u0410 \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435?<\/p>\n<details class=\"spoiler\">\n<summary>\u0410 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0442 \u0442\u0430\u043a:<\/summary>\n<div class=\"spoiler__content\">\n<p><code>404<\/code><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/dac\/46b\/2c9\/dac46b2c96db1577e29f02532d3cdf69.png\" width=\"1600\" height=\"238\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/dac\/46b\/2c9\/dac46b2c96db1577e29f02532d3cdf69.png\"\/><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0410 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432\u0441\u0435 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0432 \u043d\u0430\u0448\u0435\u043c <code>permission<\/code>-\u043a\u043b\u0430\u0441\u0441\u0435.<\/p>\n<p>\u0410 \u043c\u0435\u0442\u043e\u0434\u0430 \u0442\u0430\u043c \u0434\u0432\u0430:<\/p>\n<ul>\n<li>\n<p><code>has_permission<\/code> &#8212; \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435;<\/p>\n<\/li>\n<li>\n<p><code>has_object_permission<\/code> &#8212; \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0441 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 &#8212; \u043f\u043e\u0441\u0442\u043e\u043c).<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442, \u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c <code>get_object_permission<\/code>. \u0422\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435: Django \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442 <code>get_queryset<\/code> \u0438 \u043e\u0442 \u043d\u0435\u0433\u043e \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c <code>.get()<\/code> \u043d\u0430\u0448\u0435\u0439 \u0437\u0430\u043f\u0438\u0441\u0438, \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u0442 \u0438 \u0441\u0432\u0430\u043b\u0438\u0442\u0441\u044f \u0432 <code>404<\/code> \u0442\u0430\u043a \u0438 \u043d\u0435 \u0434\u043e\u0439\u0434\u044f \u0434\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0432 <code>permission<\/code>-\u043a\u043b\u0430\u0441\u0441\u0435.\u00a0<\/p>\n<p>\u041d\u043e, \u0435\u0441\u043b\u0438 \u043c\u044b \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c, \u0442\u043e \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043c <code>403<\/code>. \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430 \u0432 <code>has_permission<\/code>.\u00a0(<a href=\"https:\/\/github.com\/encode\/django-rest-framework\/blob\/master\/rest_framework\/permissions.py#L142\" rel=\"noopener noreferrer nofollow\">\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0430<\/a>)<\/p>\n<pre><code class=\"python\">class IsAuthenticated(BasePermission):    \"\"\"    Allows access only to authenticated users.    \"\"\"      def has_permission(self, request, view):        return bool(request.user and request.user.is_authenticated) <\/code><\/pre>\n<p>\u0410 <code>has_permission<\/code> \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u043e \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u0434\u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f <code>queryset<\/code>.<\/p>\n<p>\u0418 \u0441\u043d\u043e\u0432\u0430 \u0441\u043f\u0430\u0441\u0438\u0431\u043e, Django!<\/p>\n<h3>\u041f\u0443\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u0443\u0441\u0430<\/h3>\n<p>\u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u043e\u0435\u0434\u0438\u043d\u043e \u0432\u0441\u0451, \u043e \u0447\u0435\u043c \u043c\u044b \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b\u0438 \u0432 \u0442\u0435\u043a\u0441\u0442\u0435.\u00a0<\/p>\n<p>\u041f\u043e\u0440\u044f\u0434\u043e\u043a \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439:<\/p>\n<ul>\n<li>\n<p>\u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043b\u0438 url \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 &#8212; \u043d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0431\u0443\u0434\u0435\u0442 404;<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043b\u0438 http \u043c\u0435\u0442\u043e\u0434 &#8212; \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u0438 \u043d\u0435\u0443\u0434\u0430\u0447\u0435 \u0431\u0443\u0434\u0435\u0442 405;<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c <code>has_permission<\/code> \u0438\u0437 <code>permission_classes<\/code> &#8212; \u0442\u0443\u0442 403;<\/p>\n<\/li>\n<li>\n<p><code>get_queryset<\/code> \u0438\u0437 <code>ViewSet<\/code> &#8212; \u0442\u0443\u0442 404;<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c <code>has_object_permission<\/code> &#8212; \u0442\u0443\u0442 \u0441\u043d\u043e\u0432\u0430 403.<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u0441\u0442\u0430\u0442\u0438, \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0437\u0430\u0431\u0430\u0432\u043d\u044b\u0439 \u043d\u044e\u0430\u043d\u0441: \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0435 \u043c\u0435\u0442\u043e\u0434\u044b <code>retrieve<\/code>, <code>update<\/code>, <code>delete<\/code> \u0432 \u0441\u0432\u043e\u0435\u043c <code>ViewSet<\/code>, \u0442\u043e <code>has_object_permission<\/code> \u043c\u043e\u0436\u0435\u0442 \u0438 \u043d\u0435 \u0432\u044b\u0437\u0432\u0430\u0442\u044c\u0441\u044f. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 <a href=\"https:\/\/stackoverflow.com\/a\/69960094\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<h3>\u0412\u043c\u0435\u0441\u0442\u043e \u0432\u044b\u0432\u043e\u0434\u043e\u0432<\/h3>\n<p>\u041a\u0430\u043a \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u0441\u044f, \u0435\u0436\u0438\u043a\u0438 \u043a\u043e\u043b\u043e\u043b\u0438\u0441\u044c, \u043f\u043b\u0430\u043a\u0430\u043b\u0438, \u043d\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u043b\u0438 <s>\u0436\u0440\u0430\u0442\u044c \u043a\u0430\u043a\u0442\u0443\u0441 <\/s>\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c REST \u043d\u0430 Django.\u00a0<\/p>\n<p>\u041a\u0430\u043a\u0438\u0445-\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u044d\u0442\u043e \u043e\u0431\u043e\u0439\u0442\u0438, \u043a\u0440\u043e\u043c\u0435 \u043a\u0430\u043a \u043d\u0435 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c get_queryset \u0438\u043b\u0438 \u0432\u044b\u043a\u0438\u0434\u044b\u0432\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u044b\u0435 \u0441\u0442\u0430\u0442\u0443\u0441\u044b \u0432 \u043d\u0443\u0436\u043d\u044b\u0445 \u0440\u0443\u0447\u043a\u0430\u0445 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u0439\u0434\u0435\u043d\u043e \u043d\u0435 \u0431\u044b\u043b\u043e. \u041d\u0430\u0434\u0435\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u043a\u043e\u043c\u0443-\u0442\u043e \u044d\u0442\u043e\u0442 \u0442\u0435\u043a\u0441\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442 \u043f\u0430\u0440\u0443 \u043d\u0435\u0440\u0432\u043d\u044b\u0445 \u043a\u043b\u0435\u0442\u043e\u043a \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0430\u0445 \u043f\u043e\u043d\u044f\u0442\u044c, \u043f\u043e\u0447\u0435\u043c\u0443 \u0432\u043c\u0435\u0441\u0442\u043e 404 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 403 \u0438\u043b\u0438 405.\u00a0<\/p>\n<hr\/>\n<p><em>\u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0439\u0442\u0435\u0441\u044c \u043d\u0430 \u043d\u0430\u0448 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c-\u043a\u0430\u043d\u0430\u043b\u00a0<\/em><a href=\"https:\/\/t.me\/+vvm8PwCuv-EyZGY6\" rel=\"noopener noreferrer nofollow\"><em>\u00ab\u0413\u043e\u043b\u043e\u0441 \u0422\u0435\u0445\u043d\u043e\u043a\u0440\u0430\u0442\u0438\u0438\u00bb<\/em><\/a><em>. \u041a\u0430\u0436\u0434\u043e\u0435 \u0443\u0442\u0440\u043e \u043c\u044b \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u043c \u043d\u043e\u0432\u043e\u0441\u0442\u043d\u043e\u0439 \u0434\u0430\u0439\u0434\u0436\u0435\u0441\u0442 \u0438\u0437 \u043c\u0438\u0440\u0430 \u0418\u0422, \u0430 \u043f\u043e \u0432\u0435\u0447\u0435\u0440\u0430\u043c \u0434\u0435\u043b\u0438\u043c\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c\u0438 \u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c\u0438 \u0441\u0442\u0430\u0442\u044c\u044f\u043c\u0438.<\/em><\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><\/p>\n<div class=\"tm-article-poll-container\"><!--[--><\/p>\n<div class=\"tm-article-poll tm-article-poll_variant-bordered\">\n<div class=\"tm-notice tm-notice_positive tm-article-poll__notice\"><!----><\/p>\n<div class=\"tm-notice__inner\"><!----><\/p>\n<div class=\"tm-notice__content\" data-test-id=\"notice-content\"><!--[--><span>\u0422\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043c\u043e\u0433\u0443\u0442 \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u043e\u043f\u0440\u043e\u0441\u0435. <a rel=\"nofollow\" href=\"\/kek\/v1\/auth\/habrahabr\/?back=\/ru\/articles\/729844\/&#038;hl=ru\">\u0412\u043e\u0439\u0434\u0438\u0442\u0435<\/a>, \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430.<\/span><!--]--><\/div>\n<\/div>\n<\/div>\n<p><!--[--><\/p>\n<div class=\"tm-article-poll__header\">\u0410 \u0432\u044b \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043b\u0438 REST \u043d\u0430 Django?<\/div>\n<div class=\"tm-article-poll__answers\"><!--[--><\/p>\n<div class=\"tm-article-poll__answer\">\n<div class=\"tm-article-poll__answer-data\"><span class=\"tm-article-poll__answer-percent\">25% <\/span><span class=\"tm-article-poll__answer-label\">\u0414\u0430, \u0431\u044b\u043b\u043e \u0431\u043e\u043b\u044c\u043d\u043e<\/span><span class=\"tm-article-poll__answer-votes\">5<\/span><\/div>\n<div class=\"tm-article-poll__answer-bar\">\n<div class=\"tm-article-poll__answer-progress\" style=\"width: 25%\"><\/div>\n<\/div>\n<\/div>\n<div class=\"tm-article-poll__answer\">\n<div class=\"tm-article-poll__answer-data\"><span class=\"tm-article-poll__answer-percent tm-article-poll__answer-percent_winning\">50% <\/span><span class=\"tm-article-poll__answer-label\">\u0414\u0430, \u0432\u0441\u0435 \u043f\u0440\u043e\u0448\u043b\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e<\/span><span class=\"tm-article-poll__answer-votes\">10<\/span><\/div>\n<div class=\"tm-article-poll__answer-bar\">\n<div class=\"tm-article-poll__answer-progress tm-article-poll__answer-progress_winning\" style=\"width: 50%\"><\/div>\n<\/div>\n<\/div>\n<div class=\"tm-article-poll__answer\">\n<div class=\"tm-article-poll__answer-data\"><span class=\"tm-article-poll__answer-percent\">10% <\/span><span class=\"tm-article-poll__answer-label\">\u041d\u0435, \u043d\u0430\u0444\u0438\u0433 \u043d\u0430\u0434\u043e<\/span><span class=\"tm-article-poll__answer-votes\">2<\/span><\/div>\n<div class=\"tm-article-poll__answer-bar\">\n<div class=\"tm-article-poll__answer-progress\" style=\"width: 10%\"><\/div>\n<\/div>\n<\/div>\n<div class=\"tm-article-poll__answer\">\n<div class=\"tm-article-poll__answer-data\"><span class=\"tm-article-poll__answer-percent\">15% <\/span><span class=\"tm-article-poll__answer-label\">REST \u043d\u0430 Django? \u0417\u0430\u0447\u0435\u043c?<\/span><span class=\"tm-article-poll__answer-votes\">3<\/span><\/div>\n<div class=\"tm-article-poll__answer-bar\">\n<div class=\"tm-article-poll__answer-progress\" style=\"width: 15%\"><\/div>\n<\/div>\n<\/div>\n<p><!--]--><\/div>\n<div class=\"tm-article-poll__stats\"> \u041f\u0440\u043e\u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043b\u0438 20 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439.   \u0412\u043e\u0437\u0434\u0435\u0440\u0436\u0430\u043b\u0438\u0441\u044c 3 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. <\/div>\n<p><!--]--><\/div>\n<p><!--]--><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/729844\/\"> https:\/\/habr.com\/ru\/articles\/729844\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\">\n<div><figcaption>\u042d\u0442\u043e \u044f \u0443\u0435\u0437\u0436\u0430\u044e \u0432 \u0437\u0430\u043a\u0430\u0442, \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u043f\u044b\u0442\u043e\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c REST \u043d\u0430 Django.<\/figcaption><\/div>\n<\/figure>\n<p>\u0418\u0434\u0435\u044f \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0439 REST \u043d\u0430 Django \u2013 \u0443\u0442\u043e\u043f\u0438\u044f, \u043d\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0435 \u0438 \u043d\u0435\u0442 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e, \u0447\u0442\u043e \u043e\u0431 \u044d\u0442\u043e\u043c \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c. \u041d\u0438\u0436\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u043f\u0440\u043e \u0442\u043e, \u043a\u0430\u043a \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 <code>ViewSet<\/code> \u043e\u0442 <code>GenericViewSet<\/code> \u0438 \u043f\u0430\u0440\u044b \u043c\u0438\u043a\u0441\u0438\u043d\u043e\u0432 \u0432 DRF, \u043f\u043e\u043a\u0440\u044b\u043b\u0438 \u044d\u0442\u043e \u0432\u0441\u0435 \u0442\u0435\u0441\u0442\u0430\u043c\u0438 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043c\u0435\u0441\u0442\u0430\u043c\u0438 \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0435, \u043d\u043e \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043a\u043e\u0434\u044b \u043e\u0442\u0432\u0435\u0442\u043e\u0432.<\/p>\n<p>\u0422\u0435\u043a\u0441\u0442 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u0435\u043d \u043d\u043e\u0432\u0438\u0447\u043a\u0430\u043c (\u0438\u043b\u0438 \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0448\u0430\u0440\u0435\u043d\u043d\u044b\u043c) \u0432 Django, \u0434\u0430\u0431\u044b \u0443\u043b\u043e\u0436\u0438\u0442\u044c \u0432 \u0433\u043e\u043b\u043e\u0432\u0435 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 url\u2019\u043e\u0432 \u0438 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 permission-\u043a\u043b\u0430\u0441\u0441\u043e\u0432. \u041d\u0443 \u0430 \u0431\u044b\u0432\u0430\u043b\u044b\u0435 \u0441\u043a\u0430\u0436\u0443\u0442, \u0447\u0442\u043e \u0432\u0441\u0435 \u044d\u0442\u043e \u0431\u0430\u043b\u043e\u0432\u0441\u0442\u0432\u043e \u0438 \u043d\u0430\u0434\u043e \u0431\u044b\u043b\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>GenericApiView<\/code>.<\/p>\n<h3>\u041c\u0430\u0440\u0448\u0440\u0443\u0442 \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d. 404 \u0438\u043b\u0438 405?<\/h3>\n<p>\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u0432\u0435\u0431 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f &#8212; CRUD \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0420\u0435\u0448\u0438\u043b\u0438 \u043c\u044b \u043f\u043e\u0447\u0435\u043c\u0443-\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u044d\u0442\u0438\u0445 \u0446\u0435\u043b\u0435\u0439 <code>ViewSet<\/code>, \u043d\u043e \u0440\u0443\u0447\u043a\u0438 \u043d\u0443\u0436\u043d\u044b \u0431\u044b\u043b\u0438 \u043d\u0435 \u0432\u0441\u0435 \u0438 \u0447\u0442\u043e\u0431\u044b \u043b\u0438\u0448\u043d\u0435\u0435 \u043d\u0435 \u0432\u044b\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u0442\u044c, \u0432\u0437\u044f\u043b\u0438 <code>GenericViewSet<\/code> \u0438 \u043d\u0443\u0436\u043d\u044b\u0439 <code>Mixin<\/code>. <\/p>\n<details class=\"spoiler\">\n<summary>\u0417\u0430\u0447\u0435\u043c \u0442\u0430\u043a \u0441\u043b\u043e\u0436\u043d\u043e?<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0414\u0430, \u0432\u044b\u0431\u043e\u0440 \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0439, \u043d\u043e \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u0443\u043c\u0430\u043b\u0447\u0438\u0432\u0430\u0435\u0442 \u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u0445 \u0442\u0430\u043a\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u0447\u0442\u043e \u0438\u043c\u0435\u0435\u043c \u0447\u0442\u043e \u0438\u043c\u0435\u0435\u043c.<\/p>\n<\/div>\n<\/details>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u0443:<\/p>\n<pre><code class=\"python\">class UsersViewSet(mixins.UpdateModelMixin, GenericViewSet):     pass <\/code><\/pre>\n<p>\u0412\u0441\u0435, \u0447\u0442\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0430\u0441 \u043f\u043e\u043a\u0430 \u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043f\u0443\u0441\u0442\u0438\u043c \u044d\u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442.\u00a0<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b\u0438 \u0432\u043e\u0442 \u0442\u0430\u043a\u0438\u0435 \u043f\u0443\u0442\u0438:<\/p>\n<pre><code class=\"python\">router = SimpleRouter() router.register(\"users\", UsersViewSet, basename=\"users\")<\/code><\/pre>\n<p>\u0418 \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043d\u0430\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0447\u0442\u043e \u043b\u0438\u0448\u043d\u0438\u0435 \u0440\u0443\u0447\u043a\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b (\u0447\u0442\u043e\u0431\u044b \u0432\u0441\u044f\u043a\u0438\u0435 \u0442\u0430\u043c \u043c\u0438\u043c\u043e\u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043b\u044b \u0438\u0445 \u043d\u0435 \u0442\u0440\u043e\u0433\u0430\u043b\u0438) \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 \u044d\u0442\u043e \u0432\u0441\u0435 \u0434\u0435\u043b\u043e \u0442\u0435\u0441\u0442\u043e\u0432.<\/p>\n<pre><code class=\"python\">def test_list_user(auth_free_client_and_user):    client, user = auth_free_client_and_user      response = client.get(\"\/api\/users\/\")    assert response.status_code == 404, response.json()   def test_delete_user(auth_free_client_and_user):    client, user = auth_free_client_and_user      response = client.delete(f\"\/api\/users\/{user.id}\/\")    assert response.status_code == 404, response.json()<\/code><\/pre>\n<p><strong>\u0412\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0432\u043e\u043f\u0440\u043e\u0441:<\/strong> \u0431\u0443\u0434\u0435\u0442 \u043b\u0438 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c?\u00a0<\/p>\n<details class=\"spoiler\">\n<summary>\u041e\u0442\u0432\u0435\u0442 \u0443\u0431\u0438\u043b<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041d\u0435\u0442<\/p>\n<figure class=\"full-width\"><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0427\u0435\u043b\u043e\u0432\u0435\u043a\u0443, \u043d\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u0437\u043d\u0430\u043a\u043e\u043c\u043e\u043c\u0443 \u0441 DRF \u043f\u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043d\u0430\u0448\u0438 \u0442\u0435\u0441\u0442\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u041d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043e\u043d\u0438 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442.\u00a0\u0410 \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u043f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u0432 \u043a\u043b\u0430\u0441\u0441 <code>Router<\/code> \u0438\u0437 DRF, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u044d\u0442\u0443 \u043e\u0448\u0438\u0431\u043a\u0443. <\/p>\n<h4>\u041a\u0430\u043a \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043c\u0430\u0440\u0448\u0440\u0443\u0442<\/h4>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 DRF, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u044e\u0442 \u043f\u043e\u0447\u0435\u043c\u0443 \u0442\u0435\u0441\u0442\u044b \u043f\u0430\u0434\u0430\u044e\u0442 \u0438 \u0432\u044b\u0434\u0430\u044e\u0442 \u043d\u0435 \u0442\u0435 http-\u0441\u0442\u0430\u0442\u0443\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0436\u0438\u0434\u0430\u043b\u0438\u0441\u044c. \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0435\u043d \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u043b\u0438\u0441\u0442\u0430\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u0434\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430.\u00a0<\/p>\n<p>\u041f\u0440\u0438\u0447\u0438\u043d\u0430 AssertionError \u0432 \u0442\u0435\u0441\u0442\u0435 \u0432 \u0442\u043e\u043c, \u043a\u0430\u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 <code>Router<\/code>. \u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 <code>SimpleRouter<\/code> \u0438\u0437 DRF \u0443\u0432\u0438\u0434\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 (<a href=\"https:\/\/github.com\/encode\/django-rest-framework\/blob\/master\/rest_framework\/routers.py#L93\" rel=\"noopener noreferrer nofollow\">\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0430<\/a>):<\/p>\n<pre><code class=\"python\">class SimpleRouter(BaseRouter):      routes = [        # List route.        Route(            url=r'^{prefix}{trailing_slash}$',            mapping={                'get': 'list',                'post': 'create'            },            name='{basename}-list',            detail=False,            initkwargs={'suffix': 'List'}        ),        # Dynamically generated list routes. Generated using        # @action(detail=False) decorator on methods of the viewset.        DynamicRoute(            url=r'^{prefix}\/{url_path}{trailing_slash}$',            name='{basename}-{url_name}',            detail=False,            initkwargs={}        ),        # Detail route.        Route(            url=r'^{prefix}\/{lookup}{trailing_slash}$',            mapping={                'get': 'retrieve',                'put': 'update',                'patch': 'partial_update',                'delete': 'destroy'            },            name='{basename}-detail',            detail=True,            initkwargs={'suffix': 'Instance'}        ),        # Dynamically generated detail routes. Generated using        # @action(detail=True) decorator on methods of the viewset.        DynamicRoute(            url=r'^{prefix}\/{lookup}\/{url_path}{trailing_slash}$',            name='{basename}-{url_name}',            detail=True,            initkwargs={}        ),    ] <\/code><\/pre>\n<p>\u0427\u0442\u043e \u0432\u0430\u0436\u043d\u043e \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c:\u00a0<\/p>\n<ul>\n<li>\n<p>\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u0437 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 <code>Route<\/code><\/p>\n<\/li>\n<li>\n<p>\u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0435 \u0437\u0430\u0434\u0430\u044e\u0442\u0441\u044f:<\/p>\n<ul>\n<li>\n<p><code>url<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u00a0<\/p>\n<\/li>\n<li>\n<p><code>mapping<\/code> &#8212; \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u0437 http-\u043c\u0435\u0442\u043e\u0434\u0430 \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u043d\u0430\u0448\u0435\u0433\u043e <code>ViewSet<\/code>\u00a0<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u0415\u0449\u0435 \u043d\u0430\u043c \u0432\u0430\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432 \u044d\u0442\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 (<a href=\"https:\/\/github.com\/encode\/django-rest-framework\/blob\/master\/rest_framework\/routers.py#L226\" rel=\"noopener noreferrer nofollow\">\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0430<\/a>):\u00a0<\/p>\n<pre><code class=\"python\">def get_method_map(self, viewset, method_map):    \"\"\"    Given a viewset, and a mapping of http methods to actions,    return a new mapping which only includes any mappings that    are actually implemented by the viewset.    \"\"\"    bound_methods = {}    for method, action in method_map.items():        if hasattr(viewset, action):            bound_methods[method] = action    return bound_methods <\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c <code>method_map<\/code> \u044d\u0442\u043e mapping \u0438\u0437 \u043d\u0430\u0448\u0438\u0445 <code>Route<\/code>.\u00a0<\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0434\u043b\u044f:<\/p>\n<pre><code class=\"python\">url=r'^{prefix}{trailing_slash}$' - \u043d\u0435 \u0432\u0435\u0440\u043d\u0435\u0442\u0441\u044f \u043d\u0438\u0447\u0435\u0433\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0438\u0437 mapping \u043d\u0435\u0442 \u0432 \u043d\u0430\u0448\u0435\u043c ViewSet url=r'^{prefix}\/{lookup}{trailing_slash}$' - \u0432\u0435\u0440\u043d\u0435\u0442\u0441\u044f \u0441\u043b\u043e\u0432\u0430\u0440\u044c {\u201cput\u201d: \u201cupdate\u201d} <\/code><\/pre>\n<p>\u041d\u0443 \u0438 \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0435\u0441\u043b\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0432 <code>get_url<\/code> \u0432\u0441\u0435 \u0442\u043e\u0433\u043e \u0436\u0435 <code>SimpleRouter<\/code>, \u0442\u043e \u0443\u0432\u0438\u0434\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 (<a href=\"https:\/\/github.com\/encode\/django-rest-framework\/blob\/master\/rest_framework\/routers.py#L278\" rel=\"noopener noreferrer nofollow\">\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0430<\/a>):<\/p>\n<pre><code class=\"python\"># Only actions which actually exist on the viewset will be bound mapping = self.get_method_map(viewset, route.mapping) if not mapping:    continue <\/code><\/pre>\n<h2>\u0418\u0442\u043e\u0433\u043e<\/h2>\n<p>\u0418\u0437-\u0437\u0430 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0442 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043e\u0442 <code>UpdateModelMixin<\/code> <code>SimpleRouter<\/code> \u0441\u043e\u0437\u0434\u0430\u043b \u043d\u0430\u043c \u043c\u0430\u0440\u0448\u0440\u0443\u0442 \u0432\u0438\u0434\u0430 <code>\/users\/:id<\/code>, \u043d\u043e \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u043b \u0442\u0430\u043c \u0442\u043e\u043b\u044c\u043a\u043e http-\u043c\u0435\u0442\u043e\u0434\u044b PUT \u0438 PATCH. \u041d\u043e \u0434\u043b\u044f DELETE \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u043e\u0442 \u0436\u0435 \u043c\u0430\u0440\u0448\u0440\u0443\u0442, \u043d\u043e \u0434\u0440\u0443\u0433\u043e\u0439 \u043c\u0435\u0442\u043e\u0434.\u00a0<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0435\u0440\u0432\u044b\u0439 \u0442\u0435\u0441\u0442 \u043d\u0430 <code>list<\/code> \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0443\u0447\u0430\u0442\u044c\u0441\u044f \u043d\u0430 <code>\/users<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u043b\u0438 \u0438 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0432 \u043e\u0442\u0432\u0435\u0442 404, \u0430 \u0432\u043e\u0442 \u0432\u0442\u043e\u0440\u043e\u0439 \u0442\u0435\u0441\u0442 \u043d\u0430 <code>delete<\/code> \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0443\u0447\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442 \u0441 \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442 \u0432 \u043e\u0442\u0432\u0435\u0442 405.<\/p>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0435 \u0442\u0435\u0441\u0442\u044b \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">def test_list_user(auth_free_client_and_user):    client, user = auth_free_client_and_user      response = client.get(\"\/api\/users\/\")    assert response.status_code == 404, response.json()   def test_delete_user(auth_free_client_and_user):    client, user = auth_free_client_and_user      response = client.delete(f\"\/api\/users\/{user.id}\/\")    assert response.status_code == 405, response.json()<\/code><\/pre>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e, Django!<\/p>\n<h3>403 \u0438\u043b\u0438 404. \u041f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u201c\u0441\u0432\u043e\u0438\u201d \u0437\u0430\u043f\u0438\u0441\u0438.<\/h3>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b: \u043d\u0443 \u043b\u0430\u0434\u043d\u043e, \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u043d\u043e \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u043b\u043e\u0433\u0438\u0447\u043d\u043e. \u0417\u0430\u043f\u043e\u043c\u043d\u0438\u043b\u0438 \u0438 \u0440\u0430\u0437\u043e\u0448\u043b\u0438\u0441\u044c. \u041d\u043e \u043d\u0430 \u044d\u0442\u043e\u043c \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u043d\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0430\u0441\u044c \u0438 \u043d\u0430 \u0442\u043e\u043c \u0436\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043c\u044b \u0441\u043d\u043e\u0432\u0430 \u043d\u0430\u0442\u043a\u043d\u0443\u043b\u0438\u0441\u044c \u043d\u0430 \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u0442\u0430\u0442\u0443\u0441\u044b (\u0445\u043e\u0442\u044c \u0438 \u0432\u043f\u043e\u043b\u043d\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u043c\u044b\u0435).<\/p>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d <code>ViewSet<\/code> \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0435\u043c\u0443 <code>permission<\/code>-\u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0442\u043e, \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u043c\u043d\u0435 \u043a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u044d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c.<\/p>\n<pre><code class=\"python\">class PostViewSet(ModelViewSet):    permission_classes = [IsAuthenticated, UserPermission] <\/code><\/pre>\n<p><code>Permission<\/code>-\u043a\u043b\u0430\u0441\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0442\u0434\u0430\u0442\u044c \u043d\u0430\u043c 403 \u043a\u043e\u0434 \u043e\u0448\u0438\u0431\u043a\u0438 &#8212; \u0434\u043e\u0441\u0442\u0443\u043f \u0437\u0430\u043f\u0440\u0435\u0449\u0435\u043d &#8212; \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u0447\u0443\u0436\u043e\u0439 \u043f\u043e\u0441\u0442.<\/p>\n<pre><code class=\"python\">class UserPermission(permissions.BasePermission):      def has_object_permission(self, request, view, obj):        \"\"\"\u0414\u043e\u0441\u0442\u0443\u043f \u043a \u043e\u0431\u044a\u0435\u043a\u0442\u0443.\"\"\"        if view.action in {\"retrieve\", \"update\", \"partial_update\"}:            return obj.user_id == request.user.id        return False <\/code><\/pre>\n<p>\u041d\u043e \u0442\u0430\u043a\u0436\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u0442\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c <code>queryset<\/code> &#8212; \u0437\u0430\u043f\u0440\u043e\u0441, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0434\u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u0434\u043e\u0441\u0442\u0430\u0432\u0430\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u0441 \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u043c \u043f\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e.<\/p>\n<pre><code class=\"python\">class PostViewSet(ModelViewSet):    permission_classes = [IsAuthenticated, UserPermission]      def get_queryset(self):        \"\"\"\u0424\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c \u043f\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e.\"\"\"        return Post.objects.filter(user=self.request.user) <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0432\u043e \u0432\u0441\u0435\u0445 \u043c\u0435\u0442\u043e\u0434\u0430\u0445 \u043d\u0430\u0448\u0435\u0433\u043e ViewSet \u0431\u0443\u0434\u0443\u0442 \u0441\u0440\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043b\u0438\u0448\u043d\u0435\u0433\u043e. \u041d\u043e \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442 \u0435\u0441\u043b\u0438 \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0447\u0443\u0436\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e?\u00a0<\/p>\n<p>\u041e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e 403. \u0418 \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043a\u0440\u044b\u0442\u044c \u044d\u0442\u043e \u0442\u0435\u0441\u0442\u043e\u043c, \u0442\u043e \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043a\u0430\u043a-\u0442\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">def test_update_another_user(auth_client_and_user, another_user):    client, user = auth_client_and_user      response = client.patch(        f\"\/api\/posts\/{another_user.id}\/\",        {            \"text\": \"new amazing text\",        },    )      assert response.status_code == 403, response.json()<\/code><\/pre>\n<p>\u0410 \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435?<\/p>\n<details class=\"spoiler\">\n<summary>\u0410 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0442 \u0442\u0430\u043a:<\/summary>\n<div class=\"spoiler__content\">\n<p><code>404<\/code><\/p>\n<figure class=\"full-width\"><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0410 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432\u0441\u0435 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0432 \u043d\u0430\u0448\u0435\u043c <code>permission<\/code>-\u043a\u043b\u0430\u0441\u0441\u0435.<\/p>\n<p>\u0410 \u043c\u0435\u0442\u043e\u0434\u0430 \u0442\u0430\u043c \u0434\u0432\u0430:<\/p>\n<ul>\n<li>\n<p><code>has_permission<\/code> &#8212; \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435;<\/p>\n<\/li>\n<li>\n<p><code>has_object_permission<\/code> &#8212; \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0441 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 &#8212; \u043f\u043e\u0441\u0442\u043e\u043c).<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442, \u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c <code>get_object_permission<\/code>. \u0422\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435: Django \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442 <code>get_queryset<\/code> \u0438 \u043e\u0442 \u043d\u0435\u0433\u043e \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c <code>.get()<\/code> \u043d\u0430\u0448\u0435\u0439 \u0437\u0430\u043f\u0438\u0441\u0438, \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u0442 \u0438 \u0441\u0432\u0430\u043b\u0438\u0442\u0441\u044f \u0432 <code>404<\/code> \u0442\u0430\u043a \u0438 \u043d\u0435 \u0434\u043e\u0439\u0434\u044f \u0434\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0432 <code>permission<\/code>-\u043a\u043b\u0430\u0441\u0441\u0435.\u00a0<\/p>\n<p>\u041d\u043e, \u0435\u0441\u043b\u0438 \u043c\u044b \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c, \u0442\u043e \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043c <code>403<\/code>. \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430 \u0432 <code>has_permission<\/code>.\u00a0(<a href=\"https:\/\/github.com\/encode\/django-rest-framework\/blob\/master\/rest_framework\/permissions.py#L142\" rel=\"noopener noreferrer nofollow\">\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0430<\/a>)<\/p>\n<pre><code class=\"python\">class IsAuthenticated(BasePermission):    \"\"\"    Allows access only to authenticated users.    \"\"\"      def has_permission(self, request, view):        return bool(request.user and request.user.is_authenticated) <\/code><\/pre>\n<p>\u0410 <code>has_permission<\/code> \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u043e \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u0434\u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f <code>queryset<\/code>.<\/p>\n<p>\u0418 \u0441\u043d\u043e\u0432\u0430 \u0441\u043f\u0430\u0441\u0438\u0431\u043e, Django!<\/p>\n<h3>\u041f\u0443\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u0443\u0441\u0430<\/h3>\n<p>\u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u043e\u0435\u0434\u0438\u043d\u043e \u0432\u0441\u0451, \u043e \u0447\u0435\u043c \u043c\u044b \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b\u0438 \u0432 \u0442\u0435\u043a\u0441\u0442\u0435.\u00a0<\/p>\n<p>\u041f\u043e\u0440\u044f\u0434\u043e\u043a \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439:<\/p>\n<ul>\n<li>\n<p>\u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043b\u0438 url \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 &#8212; \u043d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0431\u0443\u0434\u0435\u0442 404;<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043b\u0438 http \u043c\u0435\u0442\u043e\u0434 &#8212; \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u0438 \u043d\u0435\u0443\u0434\u0430\u0447\u0435 \u0431\u0443\u0434\u0435\u0442 405;<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c <code>has_permission<\/code> \u0438\u0437 <code>permission_classes<\/code> &#8212; \u0442\u0443\u0442 403;<\/p>\n<\/li>\n<li>\n<p><code>get_queryset<\/code> \u0438\u0437 <code>ViewSet<\/code> &#8212; \u0442\u0443\u0442 404;<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c <code>has_object_permission<\/code> &#8212; \u0442\u0443\u0442 \u0441\u043d\u043e\u0432\u0430 403.<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u0441\u0442\u0430\u0442\u0438, \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0437\u0430\u0431\u0430\u0432\u043d\u044b\u0439 \u043d\u044e\u0430\u043d\u0441: \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0435 \u043c\u0435\u0442\u043e\u0434\u044b <code>retrieve<\/code>, <code>update<\/code>, <code>delete<\/code> \u0432 \u0441\u0432\u043e\u0435\u043c <code>ViewSet<\/code>, \u0442\u043e <code>has_object_permission<\/code> \u043c\u043e\u0436\u0435\u0442 \u0438 \u043d\u0435 \u0432\u044b\u0437\u0432\u0430\u0442\u044c\u0441\u044f. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 <a href=\"https:\/\/stackoverflow.com\/a\/69960094\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<h3>\u0412\u043c\u0435\u0441\u0442\u043e \u0432\u044b\u0432\u043e\u0434\u043e\u0432<\/h3>\n<p>\u041a\u0430\u043a \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u0441\u044f, \u0435\u0436\u0438\u043a\u0438 \u043a\u043e\u043b\u043e\u043b\u0438\u0441\u044c, \u043f\u043b\u0430\u043a\u0430\u043b\u0438, \u043d\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u043b\u0438 <s>\u0436\u0440\u0430\u0442\u044c \u043a\u0430\u043a\u0442\u0443\u0441 <\/s>\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c REST \u043d\u0430 Django.\u00a0<\/p>\n<p>\u041a\u0430\u043a\u0438\u0445-\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u044d\u0442\u043e \u043e\u0431\u043e\u0439\u0442\u0438, \u043a\u0440\u043e\u043c\u0435 \u043a\u0430\u043a \u043d\u0435 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c get_queryset \u0438\u043b\u0438 \u0432\u044b\u043a\u0438\u0434\u044b\u0432\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u044b\u0435 \u0441\u0442\u0430\u0442\u0443\u0441\u044b \u0432 \u043d\u0443\u0436\u043d\u044b\u0445 \u0440\u0443\u0447\u043a\u0430\u0445 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u0439\u0434\u0435\u043d\u043e \u043d\u0435 \u0431\u044b\u043b\u043e. \u041d\u0430\u0434\u0435\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u043a\u043e\u043c\u0443-\u0442\u043e \u044d\u0442\u043e\u0442 \u0442\u0435\u043a\u0441\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442 \u043f\u0430\u0440\u0443 \u043d\u0435\u0440\u0432\u043d\u044b\u0445 \u043a\u043b\u0435\u0442\u043e\u043a \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0430\u0445 \u043f\u043e\u043d\u044f\u0442\u044c, \u043f\u043e\u0447\u0435\u043c\u0443 \u0432\u043c\u0435\u0441\u0442\u043e 404 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 403 \u0438\u043b\u0438 405.\u00a0<\/p>\n<hr\/>\n<p><em>\u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0439\u0442\u0435\u0441\u044c \u043d\u0430 \u043d\u0430\u0448 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c-\u043a\u0430\u043d\u0430\u043b\u00a0<\/em><a href=\"https:\/\/t.me\/+vvm8PwCuv-EyZGY6\" rel=\"noopener noreferrer nofollow\"><em>\u00ab\u0413\u043e\u043b\u043e\u0441 \u0422\u0435\u0445\u043d\u043e\u043a\u0440\u0430\u0442\u0438\u0438\u00bb<\/em><\/a><em>. \u041a\u0430\u0436\u0434\u043e\u0435 \u0443\u0442\u0440\u043e \u043c\u044b \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u043c \u043d\u043e\u0432\u043e\u0441\u0442\u043d\u043e\u0439 \u0434\u0430\u0439\u0434\u0436\u0435\u0441\u0442 \u0438\u0437 \u043c\u0438\u0440\u0430 \u0418\u0422, \u0430 \u043f\u043e \u0432\u0435\u0447\u0435\u0440\u0430\u043c \u0434\u0435\u043b\u0438\u043c\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c\u0438 \u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c\u0438 \u0441\u0442\u0430\u0442\u044c\u044f\u043c\u0438.<\/em><\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><\/p>\n<div class=\"tm-article-poll-container\"><!--[--><\/p>\n<div class=\"tm-article-poll tm-article-poll_variant-bordered\">\n<div class=\"tm-notice tm-notice_positive tm-article-poll__notice\"><!----><\/p>\n<div class=\"tm-notice__inner\"><!----><\/p>\n<div class=\"tm-notice__content\" data-test-id=\"notice-content\"><!--[--><span><\/span><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-392667","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/392667","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=392667"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/392667\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=392667"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=392667"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=392667"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}