{"id":443369,"date":"2024-12-26T07:56:03","date_gmt":"2024-12-26T07:56:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=443369"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=443369","title":{"rendered":"<span>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 RESTful API \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Django \u0438 Django REST Framework<\/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<p>\u0412 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u043c \u043c\u0438\u0440\u0435 \u0432\u0435\u0431-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 API (Application Programming Interface) \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c\u0438 \u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438.<br \/> REST API,  \u0441\u0442\u0430\u043b\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u043c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0438\u0445 \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u0435 \u0438 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u0438.<\/p>\n<p>\u041d\u0430\u0448\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u044f\u044f \u0446\u0435\u043b\u044c &#8212;  \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432  \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f  REST API \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Django \u0438 Django REST Framework, \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u044f\u0441\u044c \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u0438 \u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043f\u043e\u0447\u0435\u043c\u0443 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 API \u0432\u0430\u0436\u043d\u043e \u0438 \u043a\u0430\u043a \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0432 \u0432\u0430\u0448\u0438\u0445 \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445.<\/p>\n<h4>\u041f\u043e\u0447\u0435\u043c\u0443 REST API \u0432\u0430\u0436\u043d\u044b?<\/h4>\n<p>REST  \u2014 \u044d\u0442\u043e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u044b\u0439 \u0441\u0442\u0438\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043d\u0430\u0431\u043e\u0440 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u0438 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u043e\u0432 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432.<\/p>\n<p>REST API \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442:<\/p>\n<ul>\n<li>\n<p><strong>\u041e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0442\u044c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c\u0438<\/strong>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c \u0447\u0435\u0440\u0435\u0437 API.<\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043d\u0443\u044e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443<\/strong>.  \u0420\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u0443\u043b\u0443\u0447\u0448\u0430\u0435\u0442 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u044c \u0438 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u044c.<\/p>\n<\/li>\n<li>\n<p><strong>\u041e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c \u0441 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0430\u043c\u0438<\/strong>.  REST API \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 HTTP-\u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a JSON, \u0447\u0442\u043e \u043e\u0431\u043b\u0435\u0433\u0447\u0430\u0435\u0442 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e \u0432 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b.<\/p>\n<\/li>\n<\/ul>\n<h4>\u041f\u043b\u0430\u043d \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043f\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435<\/h4>\n<p><strong>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043d\u0430\u0448 \u043f\u043b\u0430\u043d \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0438 \u043f\u043e\u0441\u043a\u043e\u0440\u0435\u0435 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043a\u043e\u0434\u0430!<\/strong><\/p>\n<ul>\n<li>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0438\u043c \u043f\u0440\u043e\u0435\u043a\u0442 Django \u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f API.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Django ORM.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0438\u043c Django REST Framework.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u044b \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u0421\u0434\u0435\u043b\u0430\u0435\u043c  \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044e, \u043f\u043e\u0438\u0441\u043a, \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443, \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u044e.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0448\u0435 API.<\/p>\n<\/li>\n<li>\n<p>\u0420\u0430\u0437\u0432\u0435\u0440\u043d\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442 \u0432 \u043e\u0431\u043b\u0430\u043a\u0435 <a href=\"https:\/\/amvera.ru\/?utm_source=habr&amp;utm_medium=article&amp;utm_campaign=djangoapi\">Amvera<\/a> \u0442\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c\u0438 \u0432 IDE \u0447\u0435\u0440\u0435\u0437 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u043a\u043e\u0434\u0430 \u0432 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0439 Git-\u0440\u0435\u043f\u0437\u0438\u0442\u043e\u0440\u0438\u0439 (\u0447\u0442\u043e \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0449\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 VPS).<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u044d\u0442\u0430\u043f \u043d\u0430\u0448\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438  \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0430\u0442\u044c\u0441\u044f \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u044f\u043c\u0438 \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u043a\u043e\u0434\u0430, \u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u0432\u00a0<a href=\"https:\/\/github.com\/Alpetpon\/Amvera_articles\/tree\/main\/Site\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438\u00a0\u043d\u0430\u00a0GitHub<\/a>.<\/p>\n<p>\u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0435\u043c!)<\/p>\n<h4>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c Django \u0438 Django REST Framework<\/h4>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c Django \u0438 DRF. \u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0438\u0437\u043e\u043b\u044f\u0446\u0438\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0438 \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u043c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"bash\"># \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435  python -m venv venv<\/code><\/pre>\n<pre><code class=\"bash\"># \u0410\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u044f \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f  # \u041d\u0430 Windows:  .\\venv\\Scripts\\activate   # \u041d\u0430 macOS \u0438 Linux:  source venv\/bin\/activate<\/code><\/pre>\n<h3>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043f\u0430\u043a\u0435\u0442\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b<\/h3>\n<pre><code class=\"bash\">pip install django pip install djangorestframework pip install django-filter pip install djangorestframework-simplejwt<\/code><\/pre>\n<h4>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0430\u043f\u043a\u0443  \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438 \u043d\u0430\u0448\u0435\u0433\u043e  \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/h4>\n<pre><code class=\"bash\">django-admin startproject Site cd Site python manage.py startapp api<\/code><\/pre>\n<h4>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u0438<\/h4>\n<p>\u0412 \u0444\u0430\u0439\u043b\u0435\u00a0<code>api\/models.py<\/code>\u00a0\u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438:<\/p>\n<ul>\n<li>\n<p><strong>Profile<\/strong>: \u0420\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c\u00a0<code>User<\/code>, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044f \u0431\u0438\u043e\u0433\u0440\u0430\u0444\u0438\u044e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<\/li>\n<li>\n<p><strong>Category<\/strong>: \u041a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p><strong>Post<\/strong>: \u041f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0430\u044f \u0441 \u0430\u0432\u0442\u043e\u0440\u043e\u043c (\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c) \u0438 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0435\u0439.<\/p>\n<\/li>\n<li>\n<p><strong>Comment<\/strong>: \u041a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u043a \u043f\u043e\u0441\u0442\u0443 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\">from django.db import models   from django.contrib.auth.models import User      class Profile(models.Model):       \"\"\"\u0420\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 User \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u043b\u0435\u0439\"\"\"       user = models.OneToOneField(User, on_delete=models.CASCADE)       bio = models.TextField(blank=True)          def __str__(self):           return f'\u041f\u0440\u043e\u0444\u0438\u043b\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f {self.user.username}'      class Category(models.Model):       \"\"\"\u041c\u043e\u0434\u0435\u043b\u044c \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u043e\u0432\"\"\"       name = models.CharField(max_length=100)       description = models.TextField(blank=True)          def __str__(self):           return self.name      class Post(models.Model):       \"\"\"\u041c\u043e\u0434\u0435\u043b\u044c \u043f\u043e\u0441\u0442\u0430\"\"\"       author = models.ForeignKey(User, related_name='posts', on_delete=models.CASCADE)       category = models.ForeignKey(Category, related_name='posts', on_delete=models.SET_NULL, null=True)       title = models.CharField(max_length=200)       content = models.TextField()       published = models.DateTimeField(auto_now_add=True)       updated = models.DateTimeField(auto_now=True)       likes = models.ManyToManyField(User, related_name='liked_posts', blank=True)          class Meta:           ordering = ['-published']          def __str__(self):           return self.title      class Comment(models.Model):       \"\"\"\u041c\u043e\u0434\u0435\u043b\u044c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\"\"\"       post = models.ForeignKey(Post, related_name='comments', on_delete=models.CASCADE)       author = models.ForeignKey(User, related_name='comments', on_delete=models.CASCADE)       text = models.TextField()       created = models.DateTimeField(auto_now_add=True)          class Meta:           ordering = ['created']          def __str__(self):           return f'\u041a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u043e\u0442 {self.author.username} \u043d\u0430 {self.post.title}'<\/code><\/pre>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443 \u043c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a:<\/p>\n<ul>\n<li>\n<p><strong>\u041c\u043e\u0434\u0435\u043b\u0438<\/strong>\u00a0\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f\u00a0<strong>Django ORM<\/strong>, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 Python-\u043a\u043e\u0434 \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0438\u0441\u0430\u0442\u044c SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b.<\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438 (OneToOne, ForeignKey, ManyToMany) \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438<\/p>\n<pre><code class=\"python\">python manage.py makemigrations python manage.py migrate<\/code><\/pre>\n<h4>\u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 Django REST Framework<\/h4>\n<h3>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u00a0settings.py<\/h3>\n<p>\u0412 \u0444\u0430\u0439\u043b\u0435\u00a0<code>Site\/settings.py<\/code>\u00a0\u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c\u00a0<code>DEFAULT_PAGINATION_CLASS<\/code>\u00a0\u0438\u00a0<code>PAGE_SIZE<\/code> \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0443\u0435\u043c \u043f\u0438\u043d\u0433\u0430\u0446\u0438\u044e<\/p>\n<pre><code class=\"python\">INSTALLED_APPS = [     # \u0421\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f     'rest_framework',     'rest_framework_simplejwt',     'django_filters',     # \u041d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435     'api',     # \u0412\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f Django     'django.contrib.admin',     'django.contrib.auth',     # ... \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f ]  REST_FRAMEWORK = {     'DEFAULT_AUTHENTICATION_CLASSES': (         'rest_framework_simplejwt.authentication.JWTAuthentication',  # JWT \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f         'rest_framework.authentication.SessionAuthentication',         # \u0421\u0435\u0441\u0441\u0438\u043e\u043d\u043d\u0430\u044f \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0434\u043b\u044f \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430     ),     'DEFAULT_PERMISSION_CLASSES': (         'rest_framework.permissions.IsAuthenticatedOrReadOnly',  # \u0420\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e     ),     'DEFAULT_FILTER_BACKENDS': (         'django_filters.rest_framework.DjangoFilterBackend',  # \u0424\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f         'rest_framework.filters.SearchFilter',                # \u041f\u043e\u0438\u0441\u043a         'rest_framework.filters.OrderingFilter',              # \u0421\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430     ),     'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',  # \u041f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u044f     'PAGE_SIZE': 10,  # \u0420\u0430\u0437\u043c\u0435\u0440 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b }<\/code><\/pre>\n<ul>\n<li>\n<p><strong>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 DRF \u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0430\u043a\u0435\u0442\u043e\u0432<\/strong> \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 API.<\/p>\n<\/li>\n<li>\n<p><strong>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 DRF<\/strong> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 API, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e, \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044e \u0438 \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u044e.<\/p>\n<\/li>\n<li>\n<p><strong>JWT-\u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f<\/strong> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u043e\u043a\u0435\u043d\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u044f<\/strong>\u00a0\u0443\u043b\u0443\u0447\u0448\u0430\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043e\u0431\u044a\u0435\u043c\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<\/ul>\n<h4>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u044b \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445<\/h4>\n<p>\u0421\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u044b \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u044b, \u043f\u0440\u0438\u0433\u043e\u0434\u043d\u044b\u0435 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u043f\u043e \u0441\u0435\u0442\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, JSON), \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e.<\/p>\n<p>\u0424\u0430\u0439\u043b\u00a0<code>api\/serializers.py<\/code><\/p>\n<pre><code class=\"python\">from rest_framework import serializers   from .models import Profile, Category, Post, Comment   from django.contrib.auth.models import User      class UserSerializer(serializers.ModelSerializer):       \"\"\"\u0421\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0438 User\"\"\"          class Meta:           model = User           fields = ('id', 'username')      class ProfileSerializer(serializers.ModelSerializer):       \"\"\"\u0421\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u043f\u0440\u043e\u0444\u0438\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\"\"\"       user = UserSerializer(read_only=True)          class Meta:           model = Profile           fields = ('id', 'user', 'bio')      class CommentSerializer(serializers.ModelSerializer):       \"\"\"\u0421\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\"\"\"       author = UserSerializer(read_only=True)          class Meta:           model = Comment           fields = ('id', 'author', 'text', 'created')      class PostSerializer(serializers.ModelSerializer):       \"\"\"\u0421\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0430\"\"\"       author = UserSerializer(read_only=True)       comments = CommentSerializer(many=True, read_only=True)       category = serializers.SlugRelatedField(slug_field='name', queryset=Category.objects.all())       likes_count = serializers.SerializerMethodField()          class Meta:           model = Post           fields = ('id', 'author', 'title', 'content', 'category', 'published', 'updated', 'comments', 'likes_count')          def get_likes_count(self, obj):           return obj.likes.count()      class CategorySerializer(serializers.ModelSerializer):       \"\"\"\u0421\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438\"\"\"       posts = PostSerializer(many=True, read_only=True)          class Meta:           model = Category           fields = ('id', 'name', 'description', 'posts')<\/code><\/pre>\n<ul>\n<li>\n<p><strong>\u0421\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u044b<\/strong>\u00a0\u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044e\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442 JSON \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u043f\u043e API.<\/p>\n<\/li>\n<li>\n<p>\u041e\u043d\u0438 \u0442\u0430\u043a\u0436\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0438\u043b\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u0412\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043e\u0442\u0432\u0435\u0442\u044b API.<\/p>\n<\/li>\n<\/ul>\n<h4>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/h4>\n<p>\u0432 \u0444\u0430\u0439\u043b\u0435 \u00a0<code>api\/views.py<\/code><br \/> \u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c <code>PostViewSet<\/code>\u00a0\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c\u00a0<code>filter_backends<\/code>,\u00a0<code>filterset_fields<\/code>,\u00a0<code>search_fields<\/code>\u00a0\u0438\u00a0<code>ordering_fields<\/code>  \u0433\u0434\u0435 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044e, \u043f\u043e\u0438\u0441\u043a \u0438 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443<\/p>\n<pre><code class=\"python\">from rest_framework import viewsets, permissions, filters   from django_filters.rest_framework import DjangoFilterBackend   from rest_framework.decorators import action   from rest_framework.response import Response   from .models import Profile, Category, Post, Comment   from .serializers import ProfileSerializer, CategorySerializer, PostSerializer, CommentSerializer   from .permissions import IsOwnerOrReadOnly      class ProfileViewSet(viewsets.ModelViewSet):       \"\"\"\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u0440\u043e\u0444\u0438\u043b\u0435\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439\"\"\"       queryset = Profile.objects.all()       serializer_class = ProfileSerializer       permission_classes = [permissions.IsAuthenticatedOrReadOnly]          def perform_create(self, serializer):           serializer.save(user=self.request.user)      class CategoryViewSet(viewsets.ModelViewSet):       \"\"\"\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439\"\"\"       queryset = Category.objects.all()       serializer_class = CategorySerializer       permission_classes = [permissions.IsAuthenticatedOrReadOnly]      class PostViewSet(viewsets.ModelViewSet):       \"\"\"\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u043e\u0432\"\"\"       queryset = Post.objects.all()       serializer_class = PostSerializer       permission_classes = [IsOwnerOrReadOnly]       filter_backends = [DjangoFilterBackend, filters.SearchFilter, filters.OrderingFilter]       filterset_fields = ['category__name', 'author__username']       search_fields = ['title', 'content']       ordering_fields = ['published', 'author__username', 'likes_count']          def perform_create(self, serializer):           serializer.save(author=self.request.user)          @action(detail=True, methods=['post'])       def like(self, request, pk=None):           \"\"\"\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u043b\u0430\u0439\u043a\u043d\u0443\u0442\u044c \u043f\u043e\u0441\u0442\"\"\"           post = self.get_object()           post.likes.add(request.user)           return Response({'status': '\u043f\u043e\u0441\u0442 \u043b\u0430\u0439\u043a\u043d\u0443\u0442'})          @action(detail=True, methods=['post'])       def unlike(self, request, pk=None):           \"\"\"\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0443\u0431\u0440\u0430\u0442\u044c \u043b\u0430\u0439\u043a \u0441 \u043f\u043e\u0441\u0442\u0430\"\"\"           post = self.get_object()           post.likes.remove(request.user)           return Response({'status': '\u043b\u0430\u0439\u043a \u0441 \u043f\u043e\u0441\u0442\u0430 \u0443\u0431\u0440\u0430\u043d'})      class CommentViewSet(viewsets.ModelViewSet):       \"\"\"\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432\"\"\"       queryset = Comment.objects.all()       serializer_class = CommentSerializer       permission_classes = [IsOwnerOrReadOnly]          def perform_create(self, serializer):           serializer.save(author=self.request.user)<\/code><\/pre>\n<ul>\n<li>\n<p><strong>\u0424\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f<\/strong>\u00a0\u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u044f\u043c.<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u043e\u0438\u0441\u043a<\/strong>\u00a0\u043e\u0431\u043b\u0435\u0433\u0447\u0430\u0435\u0442 \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043f\u043e \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u0430\u043c.<\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430<\/strong>\u00a0\u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435.<\/p>\n<\/li>\n<\/ul>\n<p>\u0432 \u0444\u0430\u0439\u043b\u0435 <code>api\/permissions.py<\/code> \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0435<\/p>\n<pre><code class=\"python\">from rest_framework import permissions      class IsOwnerOrReadOnly(permissions.BasePermission):       \"\"\"       \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0435\u0435 \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e.    \"\"\"       def has_object_permission(self, request, view, obj):           if request.method in permissions.SAFE_METHODS:               return True              return obj.author == request.user<\/code><\/pre>\n<ul>\n<li>\n<p><strong>\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/strong>\u00a0\u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u043e\u0439.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0442\u043e\u043b\u044c\u043a\u043e \u0430\u0432\u0442\u043e\u0440 \u043f\u043e\u0441\u0442\u0430 \u0438\u043b\u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0435\u0433\u043e \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u044f\u0442\u044c.<\/p>\n<\/li>\n<\/ul>\n<p>\u0432 \u0444\u0430\u0439\u043b\u0435 \u00a0<code>api\/urls.py<\/code> \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b \u0434\u043b\u044f API<\/p>\n<pre><code class=\"python\">from django.urls import include, path   from rest_framework import routers   from .views import ProfileViewSet, CategoryViewSet, PostViewSet, CommentViewSet      router = routers.DefaultRouter()   router.register(r'profiles', ProfileViewSet)   router.register(r'categories', CategoryViewSet)   router.register(r'posts', PostViewSet)   router.register(r'comments', CommentViewSet)      urlpatterns = [       path('', include(router.urls)),       path('api-auth\/', include('rest_framework.urls', namespace='rest_framework')),   ]<\/code><\/pre>\n<p>\u0418 \u0432 \u0444\u0430\u0439\u043b\u0435\u00a0<code>Site\/urls.py<\/code>\u00a0\u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0443\u0442\u0438 \u0434\u043b\u044f JWT-\u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438<\/p>\n<pre><code class=\"python\">from django.contrib import admin from django.urls import path, include from rest_framework_simplejwt.views import (     TokenObtainPairView,     TokenRefreshView, )  urlpatterns = [     path('admin\/', admin.site.urls),     path('', include('myapi.urls')),     path('api\/token\/', TokenObtainPairView.as_view(), name='token_obtain_pair'),     path('api\/token\/refresh\/', TokenRefreshView.as_view(), name='token_refresh'), ]<\/code><\/pre>\n<ul>\n<li>\n<p><strong>\u041c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0446\u0438\u044f<\/strong>\u00a0\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u043a\u0430\u043a\u0438\u0435 URL-\u0430\u0434\u0440\u0435\u0441\u0430 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p><strong>JWT-\u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f<\/strong>\u00a0\u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0442\u043e\u043a\u0435\u043d\u043e\u0432.<\/p>\n<\/li>\n<\/ul>\n<h4>\u041f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0448\u0435 API<\/h4>\n<p>\u0414\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043c JWT-\u0442\u043e\u043a\u0435\u043d. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c  POST-\u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430\u00a0<code>\/api\/token\/<\/code>\u00a0\u0441 \u0438\u043c\u0435\u043d\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043f\u0430\u0440\u043e\u043b\u0435\u043c.<\/p>\n<p>\u0413\u0434\u0435 <code>name<\/code>  \u0438  <code>password<\/code> \u0432\u0430\u0448\u0438 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<pre><code class=\"bash\">`curl -X POST -d \"username=name&amp;amp;password=your_password\" http:\/\/127.0.0.1:8000\/api\/token\/`<\/code><\/pre>\n<p>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435:<\/p>\n<pre><code class=\"json\">{   \"refresh\": \"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...\",   \"access\": \"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...\" }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439\u00a0<code>access<\/code>\u00a0\u0442\u043e\u043a\u0435\u043d \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0437\u0430\u0449\u0438\u0449\u0435\u043d\u043d\u044b\u043c \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c, \u0442\u0430\u043a\u0438\u043c \u043a\u0430\u043a \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u043e\u0441\u0442\u043e\u0432.<\/p>\n<p><strong>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435:<\/strong><\/p>\n<ul>\n<li>\n<p>\u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a\u00a0<code>Authorization<\/code>\u00a0\u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c\u00a0<code>Bearer your_access_token<\/code>, \u0433\u0434\u0435\u00a0<code>your_access_token<\/code>\u00a0\u2014 \u044d\u0442\u043e \u0442\u043e\u043a\u0435\u043d, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0448\u0430\u0433\u0435.<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u043e\u043c\u0430\u043d\u0434\u0430 cURL:<\/p>\n<pre><code class=\"bash\">curl -H \"Authorization: Bearer your_access_token\" http:\/\/127.0.0.1:8000\/posts\/<\/code><\/pre>\n<p>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435:<\/p>\n<pre><code class=\"json\">[   {     \"id\": 1,     \"author\": {       \"id\": 1,       \"username\": \"alex\"     },     \"title\": \"\u041f\u0435\u0440\u0432\u044b\u0439 \u043f\u043e\u0441\u0442\",     \"content\": \"\u042d\u0442\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430.\",     \"category\": \"Django\",     \"published\": \"2023-10-29T12:00:00Z\",     \"updated\": \"2023-10-29T12:00:00Z\",     \"comments\": [],     \"likes_count\": 0   } ]<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0442\u043e\u043a\u0435\u043d \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438, \u0435\u0441\u043b\u0438 \u043e\u043d \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u0435\u043d, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0448\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430\u0448\u0435\u0433\u043e API: \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u043e\u0441\u0442\u0430, \u043b\u0430\u0439\u043a \u043f\u043e\u0441\u0442\u0430 \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f.<\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u043e\u0441\u0442<\/h3>\n<p><strong>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435:<\/strong><\/p>\n<ul>\n<li>\n<p>\u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438:<\/p>\n<ul>\n<li>\n<p><code>Content-Type: application\/json<\/code><\/p>\n<\/li>\n<li>\n<p><code>Authorization: Bearer your_access_token<\/code><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u0422\u0435\u043b\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"json\">  \"title\": \"\u041d\u043e\u0432\u044b\u0439 \u043f\u043e\u0441\u0442\",   \"content\": \"\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430.\",   \"category\": \"Django\"<\/code><\/pre>\n<ul>\n<li>\n<p>\u041a\u043e\u043c\u0430\u043d\u0434\u0430 cURL:<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"bash\">curl -X POST -H \"Content-Type: application\/json\" \\      -H \"Authorization: Bearer your_access_token\" \\      -d '{\"title\": \"\u041d\u043e\u0432\u044b\u0439 \u043f\u043e\u0441\u0442\", \"content\": \"\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430.\", \"category\": \"Django\"}' \\      http:\/\/127.0.0.1:8000\/posts\/<\/code><\/pre>\n<p>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435:<\/p>\n<pre><code class=\"json\">  \"id\": 2,   \"author\": {     \"id\": 1,     \"username\": \"alex\"   },   \"title\": \"\u041d\u043e\u0432\u044b\u0439 \u043f\u043e\u0441\u0442\",   \"content\": \"\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430.\",   \"category\": \"Django\",   \"published\": \"2024-10-29T12:30:00Z\",   \"updated\": \"2024-10-29T12:30:00Z\",   \"comments\": [],   \"likes_count\": 0<\/code><\/pre>\n<h3>\u041b\u0430\u0439\u043a \u043f\u043e\u0441\u0442\u0430<\/h3>\n<p><strong>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435:<\/strong><\/p>\n<ul>\n<li>\n<p>\u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a\u00a0<code>Authorization: Bearer your_access_token<\/code><\/p>\n<\/li>\n<li>\n<p>URL \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u0441\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043b\u0430\u0439\u043a\u043d\u0443\u0442\u044c (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440,\u00a0<code>2<\/code>).<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u043e\u043c\u0430\u043d\u0434\u0430 cURL:<\/p>\n<pre><code class=\"bash\">curl -X POST -H \"Authorization: Bearer your_access_token\" \\      http:\/\/127.0.0.1:8000\/posts\/2\/like\/<\/code><\/pre>\n<p>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435:<\/p>\n<pre><code class=\"json\">{   \"status\": \"\u043f\u043e\u0441\u0442 \u043b\u0430\u0439\u043a\u043d\u0443\u0442\" }<\/code><\/pre>\n<h3>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439<\/h3>\n<p><strong>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435:<\/strong><\/p>\n<ul>\n<li>\n<p>\u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438: <\/p>\n<ul>\n<li>\n<p><code>Content-Type: application\/json<\/code><\/p>\n<\/li>\n<li>\n<p><code>Authorization: Bearer your_access_token<\/code><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u0422\u0435\u043b\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/p>\n<pre><code class=\"json\">{   \"post\": 2,   \"text\": \"\u041e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u043f\u043e\u0441\u0442!\" }<\/code><\/pre>\n<p>\u041a\u043e\u043c\u0430\u043d\u0434\u0430 cURL:<\/p>\n<pre><code class=\"bash\">curl -X POST -H \"Content-Type: application\/json\" \\      -H \"Authorization: Bearer your_access_token\" \\      -d '{\"post\": 2, \"text\": \"\u041e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u043f\u043e\u0441\u0442!\"}' \\      http:\/\/127.0.0.1:8000\/comments\/<\/code><\/pre>\n<p>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435:<\/p>\n<pre><code class=\"json\">{   \"id\": 1,   \"author\": {     \"id\": 1,     \"username\": \"alex\"   },   \"text\": \"\u041e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u043f\u043e\u0441\u0442!\",   \"created\": \"2024-10-29T12:35:00Z\" }<\/code><\/pre>\n<h4>\u0414\u0435\u043f\u043b\u043e\u0439 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 Amvera<\/h4>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0433\u043e API \u043d\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435, \u0434\u0430\u0432\u0430\u0439 \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0451\u043c \u0435\u0433\u043e \u043d\u0430 \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0431\u044b\u043b \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d 24\/7 \u0438 \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0435\u043b \u043e\u0442 \u0432\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430.<\/p>\n<h3>\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0432 \u0441\u0435\u0440\u0432\u0438\u0441\u0435 Amvera Cloud<\/h3>\n<ol>\n<li>\n<p><strong>\u0421\u043e\u0437\u0434\u0430\u0439 \u0430\u043a\u043a\u0430\u0443\u043d\u0442:<\/strong> <\/p>\n<ul>\n<li>\n<p>\u041f\u0435\u0440\u0435\u0439\u0434\u0438 \u043d\u0430 \u0441\u0430\u0439\u0442\u00a0<a href=\"https:\/\/amvera.ru\/?utm_source=habr&amp;utm_medium=article&amp;utm_campaign=djangoapi\">Amvera<\/a>.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0436\u043c\u0438 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 &#171;\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f&#187;.<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u043f\u043e\u043b\u043d\u0438 \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043f\u043e\u043b\u044f, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u043d\u043e\u043c\u0435\u0440 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0430, \u0438 \u043d\u0430\u0436\u043c\u0438 &#171;\u041e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u0434&#187;.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0432\u0435\u0434\u0438 \u043a\u043e\u0434 \u0438\u0437 SMS, \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0434\u0438, \u0447\u0442\u043e \u0442\u044b \u043d\u0435 \u0440\u043e\u0431\u043e\u0442, \u0438 \u043d\u0430\u0436\u043c\u0438 &#171;\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f&#187;.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u0442\u0432\u0435\u0440\u0434\u0438 \u0430\u0434\u0440\u0435\u0441 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b, \u043f\u0435\u0440\u0435\u0439\u0434\u044f \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 \u0432 \u043f\u0438\u0441\u044c\u043c\u0435.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/h3>\n<ol>\n<li>\n<p><strong>\u0421\u043e\u0437\u0434\u0430\u0439 \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442:<\/strong><\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0432\u0445\u043e\u0434\u0430 \u043d\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0443, \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043d\u0430\u0436\u043c\u0438 \u043a\u043d\u043e\u043f\u043a\u0443 &#171;\u0421\u043e\u0437\u0434\u0430\u0442\u044c&#187; \u0438\u043b\u0438 &#171;\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0439!&#187;.<\/p>\n<\/li>\n<\/ul>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/90a\/00c\/aa0\/90a00caa0d20e5d56d26f898a5eb9fe2.png\" alt=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/90a\/00c\/aa0\/90a00caa0d20e5d56d26f898a5eb9fe2.png\" title=\"\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\" width=\"1560\" height=\"682\" data-src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/90a\/00c\/aa0\/90a00caa0d20e5d56d26f898a5eb9fe2.png\"\/><\/p>\n<div><figcaption>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/figcaption><\/div>\n<\/figure>\n<\/li>\n<\/ol>\n<p>2.<strong>\u041d\u0430\u0441\u0442\u0440\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0442:<\/strong><\/p>\n<ul>\n<li>\n<p>\u041f\u0440\u0438\u0441\u0432\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0442\u0443 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 (\u043b\u0443\u0447\u0448\u0435 \u043d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u043c).<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0431\u0435\u0440\u0438 \u0442\u0430\u0440\u0438\u0444\u043d\u044b\u0439 \u043f\u043b\u0430\u043d. \u0414\u043b\u044f \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0433\u043e APi \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u0430\u043c\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0442\u0430\u0440\u0438\u0444\u0430.<\/p>\n<\/li>\n<\/ul>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/cae\/e8b\/b4a\/caee8bb4a9122aa9942f91307913f4eb.png\" width=\"1828\" height=\"1210\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cae\/e8b\/b4a\/caee8bb4a9122aa9942f91307913f4eb.png\"\/><\/figure>\n<ol start=\"3\">\n<li>\n<p><strong>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u044f:<\/strong><\/p>\n<\/li>\n<\/ol>\n<ul>\n<li>\n<p>Amvera \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 git \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0438 \u043a\u043e\u0434\u0430 \u0432 \u043e\u0431\u043b\u0430\u043a\u043e. \u0412\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438\u00a0<code>amvera.yml<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434\u0441\u043a\u0430\u0436\u0435\u0442 \u043e\u0431\u043b\u0430\u043a\u0443, \u043a\u0430\u043a \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0432\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u0441\u044c\u00a0<a href=\"https:\/\/manifest.amvera.ru\/\">\u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438<\/a>.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/412\/ecc\/41e\/412ecc41e95ebe6de3d798d5defb60a6.png\" width=\"1568\" height=\"1586\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/412\/ecc\/41e\/412ecc41e95ebe6de3d798d5defb60a6.png\"\/><\/figure>\n<\/li>\n<li>\n<p><strong>\u0412\u044b\u0431\u043e\u0440 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439:<\/strong><\/p>\n<ul>\n<li>\n<p>\u0423\u043a\u0430\u0436\u0438\u0442\u0435 \u0432\u0435\u0440\u0441\u0438\u044e Python \u0438 \u043f\u0443\u0442\u044c \u0434\u043e \u0444\u0430\u0439\u043b\u0430\u00a0<code>requirements.txt<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043f\u0430\u043a\u0435\u0442\u044b.<\/p>\n<\/li>\n<li>\n<p>\u0423\u043a\u0430\u0436\u0438\u0442\u0435 \u043f\u0443\u0442\u044c \u0434\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440\u00a0<code>main.py<\/code>.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0444\u0430\u0439\u043b\u0430:<\/strong><\/p>\n<ul>\n<li>\n<p>\u041d\u0430\u0436\u043c\u0438\u0442\u0435 &#171;Generate YAML&#187; \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u0430\u00a0<code>amvera.yml<\/code>\u00a0\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u0435 \u0435\u0433\u043e \u0432 \u043a\u043e\u0440\u0435\u043d\u044c \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u0424\u0430\u0439\u043b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438\u00a0<code>amvera.yml<\/code>\u00a0\u0441\u043b\u0443\u0436\u0438\u0442 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430 Amvera \u0437\u043d\u0430\u043b\u0430, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442. \u042d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043a\u043b\u044e\u0447\u0435\u0432\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0438, \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044f\u0445, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f\u0445 \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0444\u0430\u0439\u043b\u0430\u00a0<code>amvera.yml<\/code>:<\/p>\n<pre><code>meta:  environment: python  toolchain:   name: pip   version: 3.8  build:  requirementsPath: requirements.txt  run:  scriptName: manage.py  persistenceMount: \/data  containerPort: 8000<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0432 \u0441\u0440\u0435\u0434\u0435 Amvera, \u0432\u0430\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043f\u0430\u043a\u0435\u0442\u044b \u0432 \u0444\u0430\u0439\u043b\u0435\u00a0<code>requirements.txt<\/code>. \u042d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0432\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 Python, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u044b \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430.<\/p>\n<p>\u0412\u043e\u0442 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0430\u0448 \u0444\u0430\u0439\u043b <code>requirements.txt<\/code> :<\/p>\n<pre><code>Django==3.2.9 djangorestframework==3.12.4 django-filter==2.4.0 djangorestframework-simplejwt==4.7.2<\/code><\/pre>\n<p><strong>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439:<\/strong><\/p>\n<ul>\n<li>\n<p>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0439\u0442\u0435 git \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0432 \u043a\u043e\u0440\u043d\u0435 \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0435\u0449\u0435 \u043d\u0435 \u0441\u0434\u0435\u043b\u0430\u043d\u043e:<\/p>\n<pre><code class=\"bash\">git init<\/code><\/pre>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438\u0432\u044f\u0436\u0438\u0442\u0435 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u043a \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u043d\u0430 Amvera:<\/p>\n<pre><code class=\"bash\">git remote add amvera <\/code><\/pre>\n<\/li>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0438 \u0437\u0430\u0444\u0438\u043a\u0441\u0438\u0440\u0443\u0439\u0442\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"bash\">git add . git commit -m \"Initial commit\"<\/code><\/pre>\n<\/li>\n<li>\n<p>\u041e\u0442\u043f\u0440\u0430\u0432\u044c\u0442\u0435 \u043f\u0440\u043e\u0435\u043a\u0442 \u0432 \u043e\u0431\u043b\u0430\u043a\u043e:<\/p>\n<pre><code class=\"bash\">git push amvera master<\/code><\/pre>\n<\/li>\n<\/ul>\n<p><strong>\u0421\u0431\u043e\u0440\u043a\u0430 \u0438 \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/strong><\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443, \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0441\u0442\u0430\u0442\u0443\u0441 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f \u043d\u0430 &#171;\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0441\u0431\u043e\u0440\u043a\u0430&#187;. \u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0441\u0431\u043e\u0440\u043a\u0438 \u043f\u0440\u043e\u0435\u043a\u0442 \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u0442 \u0432 \u0441\u0442\u0430\u0434\u0438\u044e &#171;\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u0435&#187;, \u0430 \u0437\u0430\u0442\u0435\u043c \u0432 \u0441\u0442\u0430\u0442\u0443\u0441 &#171;\u0423\u0441\u043f\u0435\u0448\u043d\u043e \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u043e&#187;.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0435 \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u043b\u0441\u044f, \u043f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435 \u043b\u043e\u0433\u0438 \u0441\u0431\u043e\u0440\u043a\u0438 \u0438 \u043b\u043e\u0433\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043e\u0442\u043b\u0430\u0434\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0435\u043a\u0442 \u0437\u0430\u0432\u0438\u0441 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 &#171;\u0421\u0431\u043e\u0440\u043a\u0430&#187;, \u0443\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044c \u0432 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u0438 \u0444\u0430\u0439\u043b\u0430\u00a0<code>amvera.yml<\/code><\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0437\u0434\u0440\u0430\u0432\u043b\u044f\u044e! \u041c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 REST API \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Django \u0438 Django REST Framework.<\/p>\n<hr\/>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043b\u0435\u0433\u043a\u043e \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u0438 \u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0432 \u043d\u0435\u0433\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0442\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c\u0438 \u0432 IDE, \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0439\u0442\u0435\u0441\u044c \u0432 \u043e\u0431\u043b\u0430\u043a\u0435 \u0441\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u043c CI\/CD\u00a0<a href=\"https:\/\/amvera.ru\/?utm_source=habr&amp;utm_medium=article&amp;utm_campaign=djangoapi\">Amvera Cloud<\/a>, \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 111 \u0440\u0443\u0431. \u043d\u0430 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \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\/856798\/\"> https:\/\/habr.com\/ru\/articles\/856798\/<\/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<p>\u0412 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u043c \u043c\u0438\u0440\u0435 \u0432\u0435\u0431-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 API (Application Programming Interface) \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c\u0438 \u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438.<br \/> REST API,  \u0441\u0442\u0430\u043b\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u043c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0438\u0445 \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u0435 \u0438 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u0438.<\/p>\n<p>\u041d\u0430\u0448\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u044f\u044f \u0446\u0435\u043b\u044c &#8212;  \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432  \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f  REST API \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Django \u0438 Django REST Framework, \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u044f\u0441\u044c \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u0438 \u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043f\u043e\u0447\u0435\u043c\u0443 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 API \u0432\u0430\u0436\u043d\u043e \u0438 \u043a\u0430\u043a \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0432 \u0432\u0430\u0448\u0438\u0445 \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445.<\/p>\n<h4>\u041f\u043e\u0447\u0435\u043c\u0443 REST API \u0432\u0430\u0436\u043d\u044b?<\/h4>\n<p>REST  \u2014 \u044d\u0442\u043e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u044b\u0439 \u0441\u0442\u0438\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043d\u0430\u0431\u043e\u0440 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u0438 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u043e\u0432 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432.<\/p>\n<p>REST API \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442:<\/p>\n<ul>\n<li>\n<p><strong>\u041e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0442\u044c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c\u0438<\/strong>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c \u0447\u0435\u0440\u0435\u0437 API.<\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043d\u0443\u044e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443<\/strong>.  \u0420\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u0443\u043b\u0443\u0447\u0448\u0430\u0435\u0442 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u044c \u0438 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u044c.<\/p>\n<\/li>\n<li>\n<p><strong>\u041e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c \u0441 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0430\u043c\u0438<\/strong>.  REST API \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 HTTP-\u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a JSON, \u0447\u0442\u043e \u043e\u0431\u043b\u0435\u0433\u0447\u0430\u0435\u0442 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e \u0432 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b.<\/p>\n<\/li>\n<\/ul>\n<h4>\u041f\u043b\u0430\u043d \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043f\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435<\/h4>\n<p><strong>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043d\u0430\u0448 \u043f\u043b\u0430\u043d \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0438 \u043f\u043e\u0441\u043a\u043e\u0440\u0435\u0435 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043a\u043e\u0434\u0430!<\/strong><\/p>\n<ul>\n<li>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0438\u043c \u043f\u0440\u043e\u0435\u043a\u0442 Django \u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f API.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Django ORM.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0438\u043c Django REST Framework.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u044b \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u0421\u0434\u0435\u043b\u0430\u0435\u043c  \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044e, \u043f\u043e\u0438\u0441\u043a, \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443, \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u044e.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0448\u0435 API.<\/p>\n<\/li>\n<li>\n<p>\u0420\u0430\u0437\u0432\u0435\u0440\u043d\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442 \u0432 \u043e\u0431\u043b\u0430\u043a\u0435 <a href=\"https:\/\/amvera.ru\/?utm_source=habr&amp;utm_medium=article&amp;utm_campaign=djangoapi\">Amvera<\/a> \u0442\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c\u0438 \u0432 IDE \u0447\u0435\u0440\u0435\u0437 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u043a\u043e\u0434\u0430 \u0432 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0439 Git-\u0440\u0435\u043f\u0437\u0438\u0442\u043e\u0440\u0438\u0439 (\u0447\u0442\u043e \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0449\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 VPS).<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u044d\u0442\u0430\u043f \u043d\u0430\u0448\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438  \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0430\u0442\u044c\u0441\u044f \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u044f\u043c\u0438 \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u043a\u043e\u0434\u0430, \u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u0432\u00a0<a href=\"https:\/\/github.com\/Alpetpon\/Amvera_articles\/tree\/main\/Site\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438\u00a0\u043d\u0430\u00a0GitHub<\/a>.<\/p>\n<p>\u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0435\u043c!)<\/p>\n<h4>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c Django \u0438 Django REST Framework<\/h4>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c Django \u0438 DRF. \u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0438\u0437\u043e\u043b\u044f\u0446\u0438\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0438 \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u043c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"bash\"># \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435  python -m venv venv<\/code><\/pre>\n<pre><code class=\"bash\"># \u0410\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u044f \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f  # \u041d\u0430 Windows:  .\\venv\\Scripts\\activate   # \u041d\u0430 macOS \u0438 Linux:  source venv\/bin\/activate<\/code><\/pre>\n<h3>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043f\u0430\u043a\u0435\u0442\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b<\/h3>\n<pre><code class=\"bash\">pip install django pip install djangorestframework pip install django-filter pip install djangorestframework-simplejwt<\/code><\/pre>\n<h4>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0430\u043f\u043a\u0443  \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438 \u043d\u0430\u0448\u0435\u0433\u043e  \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/h4>\n<pre><code class=\"bash\">django-admin startproject Site cd Site python manage.py startapp api<\/code><\/pre>\n<h4>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u0438<\/h4>\n<p>\u0412 \u0444\u0430\u0439\u043b\u0435\u00a0<code>api\/models.py<\/code>\u00a0\u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438:<\/p>\n<ul>\n<li>\n<p><strong>Profile<\/strong>: \u0420\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c\u00a0<code>User<\/code>, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044f \u0431\u0438\u043e\u0433\u0440\u0430\u0444\u0438\u044e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<\/li>\n<li>\n<p><strong>Category<\/strong>: \u041a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p><strong>Post<\/strong>: \u041f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0430\u044f \u0441 \u0430\u0432\u0442\u043e\u0440\u043e\u043c (\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c) \u0438 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0435\u0439.<\/p>\n<\/li>\n<li>\n<p><strong>Comment<\/strong>: \u041a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u043a \u043f\u043e\u0441\u0442\u0443 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\">from django.db import models   from django.contrib.auth.models import User      class Profile(models.Model):       \"\"\"\u0420\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 User \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u043b\u0435\u0439\"\"\"       user = models.OneToOneField(User, on_delete=models.CASCADE)       bio = models.TextField(blank=True)          def __str__(self):           return f'\u041f\u0440\u043e\u0444\u0438\u043b\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f {self.user.username}'      class Category(models.Model):       \"\"\"\u041c\u043e\u0434\u0435\u043b\u044c \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u043e\u0432\"\"\"       name = models.CharField(max_length=100)       description = models.TextField(blank=True)          def __str__(self):           return self.name      class Post(models.Model):       \"\"\"\u041c\u043e\u0434\u0435\u043b\u044c \u043f\u043e\u0441\u0442\u0430\"\"\"       author = models.ForeignKey(User, related_name='posts', on_delete=models.CASCADE)       category = models.ForeignKey(Category, related_name='posts', on_delete=models.SET_NULL, null=True)       title = models.CharField(max_length=200)       content = models.TextField()       published = models.DateTimeField(auto_now_add=True)       updated = models.DateTimeField(auto_now=True)       likes = models.ManyToManyField(User, related_name='liked_posts', blank=True)          class Meta:           ordering = ['-published']          def __str__(self):           return self.title      class Comment(models.Model):       \"\"\"\u041c\u043e\u0434\u0435\u043b\u044c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\"\"\"       post = models.ForeignKey(Post, related_name='comments', on_delete=models.CASCADE)       author = models.ForeignKey(User, related_name='comments', on_delete=models.CASCADE)       text = models.TextField()       created = models.DateTimeField(auto_now_add=True)          class Meta:           ordering = ['created']          def __str__(self):           return f'\u041a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u043e\u0442 {self.author.username} \u043d\u0430 {self.post.title}'<\/code><\/pre>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443 \u043c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a:<\/p>\n<ul>\n<li>\n<p><strong>\u041c\u043e\u0434\u0435\u043b\u0438<\/strong>\u00a0\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f\u00a0<strong>Django ORM<\/strong>, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 Python-\u043a\u043e\u0434 \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0438\u0441\u0430\u0442\u044c SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b.<\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438 (OneToOne, ForeignKey, ManyToMany) \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438<\/p>\n<pre><code class=\"python\">python manage.py makemigrations python manage.py migrate<\/code><\/pre>\n<h4>\u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 Django REST Framework<\/h4>\n<h3>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u00a0settings.py<\/h3>\n<p>\u0412 \u0444\u0430\u0439\u043b\u0435\u00a0<code>Site\/settings.py<\/code>\u00a0\u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c\u00a0<code>DEFAULT_PAGINATION_CLASS<\/code>\u00a0\u0438\u00a0<code>PAGE_SIZE<\/code> \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0443\u0435\u043c \u043f\u0438\u043d\u0433\u0430\u0446\u0438\u044e<\/p>\n<pre><code class=\"python\">INSTALLED_APPS = [     # \u0421\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f     'rest_framework',     'rest_framework_simplejwt',     'django_filters',     # \u041d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435     'api',     # \u0412\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f Django     'django.contrib.admin',     'django.contrib.auth',     # ... \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f ]  REST_FRAMEWORK = {     'DEFAULT_AUTHENTICATION_CLASSES': (         'rest_framework_simplejwt.authentication.JWTAuthentication',  # JWT \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f         'rest_framework.authentication.SessionAuthentication',         # \u0421\u0435\u0441\u0441\u0438\u043e\u043d\u043d\u0430\u044f \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0434\u043b\u044f \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430     ),     'DEFAULT_PERMISSION_CLASSES': (         'rest_framework.permissions.IsAuthenticatedOrReadOnly',  # \u0420\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e     ),     'DEFAULT_FILTER_BACKENDS': (         'django_filters.rest_framework.DjangoFilterBackend',  # \u0424\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f         'rest_framework.filters.SearchFilter',                # \u041f\u043e\u0438\u0441\u043a         'rest_framework.filters.OrderingFilter',              # \u0421\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430     ),     'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',  # \u041f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u044f     'PAGE_SIZE': 10,  # \u0420\u0430\u0437\u043c\u0435\u0440 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b }<\/code><\/pre>\n<ul>\n<li>\n<p><strong>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 DRF \u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0430\u043a\u0435\u0442\u043e\u0432<\/strong> \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 API.<\/p>\n<\/li>\n<li>\n<p><strong>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 DRF<\/strong> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 API, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e, \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044e \u0438 \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u044e.<\/p>\n<\/li>\n<li>\n<p><strong>JWT-\u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f<\/strong> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u043e\u043a\u0435\u043d\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u044f<\/strong>\u00a0\u0443\u043b\u0443\u0447\u0448\u0430\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043e\u0431\u044a\u0435\u043c\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<\/ul>\n<h4>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u044b \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445<\/h4>\n<p>\u0421\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u044b \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u044b, \u043f\u0440\u0438\u0433\u043e\u0434\u043d\u044b\u0435 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u043f\u043e \u0441\u0435\u0442\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, JSON), \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e.<\/p>\n<p>\u0424\u0430\u0439\u043b\u00a0<code>api\/serializers.py<\/code><\/p>\n<pre><code class=\"python\">from rest_framework import serializers   from .models import Profile, Category, Post, Comment   from django.contrib.auth.models import User      class UserSerializer(serializers.ModelSerializer):       \"\"\"\u0421\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0438 User\"\"\"          class Meta:           model = User           fields = ('id', 'username')      class ProfileSerializer(serializers.ModelSerializer):       \"\"\"\u0421\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u043f\u0440\u043e\u0444\u0438\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\"\"\"       user = UserSerializer(read_only=True)          class Meta:           model = Profile           fields = ('id', 'user', 'bio')      class CommentSerializer(serializers.ModelSerializer):       \"\"\"\u0421\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\"\"\"       author = UserSerializer(read_only=True)          class Meta:           model = Comment           fields = ('id', 'author', 'text', 'created')      class PostSerializer(serializers.ModelSerializer):       \"\"\"\u0421\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0430\"\"\"       author = UserSerializer(read_only=True)       comments = CommentSerializer(many=True, read_only=True)       category = serializers.SlugRelatedField(slug_field='name', queryset=Category.objects.all())       likes_count = serializers.SerializerMethodField()          class Meta:           model = Post           fields = ('id', 'author', 'title', 'content', 'category', 'published', 'updated', 'comments', 'likes_count')          def get_likes_count(self, obj):           return obj.likes.count()      class CategorySerializer(serializers.ModelSerializer):       \"\"\"\u0421\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438\"\"\"       posts = PostSerializer(many=True, read_only=True)          class Meta:           model = Category           fields = ('id', 'name', 'description', 'posts')<\/code><\/pre>\n<ul>\n<li>\n<p><strong>\u0421\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u044b<\/strong>\u00a0\u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044e\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442 JSON \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u043f\u043e API.<\/p>\n<\/li>\n<li>\n<p>\u041e\u043d\u0438 \u0442\u0430\u043a\u0436\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0438\u043b\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u0412\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043e\u0442\u0432\u0435\u0442\u044b API.<\/p>\n<\/li>\n<\/ul>\n<h4>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/h4>\n<p>\u0432 \u0444\u0430\u0439\u043b\u0435 \u00a0<code>api\/views.py<\/code><br \/> \u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c <code>PostViewSet<\/code>\u00a0\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c\u00a0<code>filter_backends<\/code>,\u00a0<code>filterset_fields<\/code>,\u00a0<code>search_fields<\/code>\u00a0\u0438\u00a0<code>ordering_fields<\/code>  \u0433\u0434\u0435 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044e, \u043f\u043e\u0438\u0441\u043a \u0438 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443<\/p>\n<pre><code class=\"python\">from rest_framework import viewsets, permissions, filters   from django_filters.rest_framework import DjangoFilterBackend   from rest_framework.decorators import action   from rest_framework.response import Response   from .models import Profile, Category, Post, Comment   from .serializers import ProfileSerializer, CategorySerializer, PostSerializer, CommentSerializer   from .permissions import IsOwnerOrReadOnly      class ProfileViewSet(viewsets.ModelViewSet):       \"\"\"\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u0440\u043e\u0444\u0438\u043b\u0435\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439\"\"\"       queryset = Profile.objects.all()       serializer_class = ProfileSerializer       permission_classes = [permissions.IsAuthenticatedOrReadOnly]          def perform_create(self, serializer):           serializer.save(user=self.request.user)      class CategoryViewSet(viewsets.ModelViewSet):       \"\"\"\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439\"\"\"       queryset = Category.objects.all()       serializer_class = CategorySerializer       permission_classes = [permissions.IsAuthenticatedOrReadOnly]      class PostViewSet(viewsets.ModelViewSet):<\/code><\/pre>\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-443369","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/443369","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=443369"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/443369\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=443369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=443369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=443369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}