{"id":372463,"date":"2024-05-21T05:12:53","date_gmt":"2024-05-21T05:12:53","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=372463"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-05-21T05:12:53","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=372463","title":{"rendered":"<span>Django + React. \u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0435\u0441\u0441\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430\u043c\u0438<\/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\u0435\u043c \u0437\u0434\u0440\u0430\u0432\u0438\u044f! \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0435\u0441\u0441\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 Django \u0438 React, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0445\u0441\u044f \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0434\u043e\u043c\u0435\u043d\u0430\u0445, \u0442.\u0435 \u0441\u043b\u0443\u0447\u0430\u0439 &#171;cross-origin&#187;. \u042f \u0432 \u0434\u0432\u0443\u0445 \u0441\u043b\u043e\u0432\u0430\u0445 \u0434\u043e\u043d\u0435\u0441\u0443 \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0430\u0431\u043e\u0442\u044b, \u043f\u0440\u0438\u0447\u0438\u043d\u044b \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0439 \u0438 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0439, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u0437\u0434\u0435\u0441\u044c, \u043e\u0441\u0442\u0430\u0432\u043b\u044e \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438 \u0438 \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043a\u043e\u0434 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435\u043c \u0441\u0432\u043e\u0438\u0445 \u0448\u0430\u0433\u043e\u0432. \u041a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 &#8212; \u043e\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430 <a href=\"https:\/\/github.com\/VlassaDassa\/django-react-cookie-auth\" rel=\"noopener noreferrer nofollow\">GitHub<\/a>.<\/p>\n<h2>\u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0435\u0441\u0441\u0438\u0439<\/h2>\n<p>\u041a\u0430\u043a \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432\u0432\u043e\u0434\u0438\u0442 \u0434\u0430\u043d\u043d\u044b\u0435, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440;<\/p>\n<\/li>\n<li>\n<p>\u0421\u0435\u0440\u0432\u0435\u0440 \u0438\u0445 \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u0442, \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0441\u0435\u0441\u0441\u0438\u044e, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 cookie \u0438 \u043e\u0442\u0441\u044b\u043b\u0430\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e session_id. \u0421\u0435\u0440\u0432\u0435\u0440 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a <code>Set-Cookie: session_id=id<\/code><\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043a\u043b\u0438\u0435\u043d\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043e\u0442\u0432\u0435\u0442, \u0432 \u0435\u0433\u043e cookie \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 Set-Cookie \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f ID \u0441\u0435\u0441\u0441\u0438\u0438<\/p>\n<\/li>\n<li>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043a \u0441\u0435\u0440\u0432\u0435\u0440\u0443, \u043a\u043b\u0438\u0435\u043d\u0442 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0432\u0441\u0435 \u0441\u0432\u043e\u0438 cookies, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0435\u0441\u0442\u044c session_id. \u0421\u0435\u0440\u0432\u0435\u0440 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0435\u0441\u0442\u044c \u043b\u0438 \u044d\u0442\u0430 \u0441\u0435\u0441\u0441\u0438\u044f, \u0436\u0438\u0432\u0430 \u043b\u0438 \u043e\u043d\u0430 \u0438 \u0434\u0430\u0451\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u043c<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u0438\u0437 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0441\u0435\u0441\u0441\u0438\u044f \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f \u0438 \u043d\u044b\u043d\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0439\u0441\u044f id \u0441\u0435\u0441\u0441\u0438\u0438 \u0443\u0436\u0435 \u043d\u0435\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u0435\u043d \u0438 \u043f\u0440\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445, \u044e\u0437\u0435\u0440\u0443 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043a\u0430\u0437\u0430\u043d\u043e \u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u0435<\/p>\n<\/li>\n<\/ul>\n<h2>\u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430<\/h2>\n<p>\u041d\u0430 \u043f\u0443\u0442\u0438 \u0441\u0435\u0441\u0441\u0438\u0438 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 CSRF-\u0430\u0442\u0430\u043a\u0438, \u043f\u0443\u0433\u0430\u044e\u0449\u0438\u0435 \u0441\u0432\u043e\u0435\u0439 \u0438\u0437\u043e\u0449\u0440\u0451\u043d\u043d\u043e\u0441\u0442\u044c\u044e \u0438 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e\u043c cookies, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0442\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0434\u043e\u043c\u0435\u043d, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u043d\u0438 \u0431\u044b\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u044b. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0438\u0437 \u044d\u0442\u043e\u0439 <a href=\"https:\/\/habr.com\/ru\/companies\/oleg-bunin\/articles\/412855\/\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0430\u0442\u044c\u0438<\/a>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u0441\u043c\u044b\u0441\u043b \u044d\u0442\u0438\u0445 \u0430\u0442\u0430\u043a \u0438 \u043a\u0430\u043a \u043e\u0442 \u043d\u0438\u0445 \u0437\u0430\u0449\u0438\u0449\u0430\u0442\u044c\u0441\u044f, \u043d\u043e \u0443\u0432\u0435\u0440\u0435\u043d, \u0447\u0442\u043e \u0434\u043e\u0447\u0438\u0442\u0430\u0435\u0442\u0435 \u0434\u043e \u043a\u043e\u043d\u0446\u0430, \u0432\u0435\u0434\u044c \u044d\u0442\u043e \u0432\u0435\u0441\u044c\u043c\u0430 \u043b\u044e\u0431\u043e\u043f\u044b\u0442\u043d\u043e.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043a\u0440\u0430\u0442\u043a\u043e \u043e\u0431 CSRF-\u0443\u044f\u0437\u0432\u0438\u043c\u043e\u0441\u0442\u0438: \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0430 \u0432\u0430\u0441 \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u043e\u0431\u0440\u0430\u0437\u043e\u043c &#171;\u0440\u0435\u0434\u0438\u0440\u0435\u043a\u0442\u044f\u0442&#187; \u043d\u0430 \u0442\u043e\u0442 \u0434\u043e\u043c\u0435\u043d, \u0433\u0434\u0435 \u0432\u044b, \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043c\u043e\u0436\u0435\u0442\u0435 \u0431\u044b\u0442\u044c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u0438 \u0433\u0434\u0435 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0435 \u0441\u0430\u043c\u044b\u0435 cookie. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 cookie \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0430 \u0434\u043e\u043c\u0435\u043d, \u0442\u043e \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u0440\u043e\u0439\u0434\u0451\u0442 \u043a\u0430\u043a \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439. \u0422.\u0435 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a \u0441\u043c\u043e\u0436\u0435\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043e\u0442 \u0432\u0430\u0448\u0435\u0433\u043e \u043b\u0438\u0446\u0430.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u043b\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 CSRF-\u0442\u043e\u043a\u0435\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u043e\u0440\u0430\u0437\u043e\u0432\u044b\u043c. \u041f\u0440\u0438 \u043e\u043f\u0430\u0441\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u0445, \u0433\u0434\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0442\u043e\u0442 \u0437\u0430 \u043a\u043e\u0433\u043e \u0441\u0435\u0431\u044f \u0432\u044b\u0434\u0430\u0451\u0442 (POST, DELETE \u0438 \u0442.\u043f), \u0435\u043c\u0443 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f CSRF-\u0442\u043e\u043a\u0435\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043d \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442 \u0432 cookie \u0432\u043c\u0435\u0441\u0442\u0435 \u0441\u043e \u0441\u0432\u043e\u0438\u043c \u043e\u043f\u0430\u0441\u043d\u044b\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c. \u041d\u0430 \u0441\u0430\u0439\u0442\u0435 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0430 \u0431\u044b \u0442\u0430\u043a\u043e\u0435 \u043d\u0435 \u043f\u0440\u043e\u043a\u0430\u0442\u0438\u043b\u043e, \u0435\u043c\u0443 \u0431\u044b \u043d\u0438\u043a\u0442\u043e \u043f\u043e\u043f\u0440\u043e\u0441\u0442\u0443 \u043d\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043b \u044d\u0442\u043e\u0442 \u0442\u043e\u043a\u0435\u043d. \u042d\u0442\u043e \u043b\u0438\u0448\u044c \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0437\u0430\u0449\u0438\u0442\u044b.<\/p>\n<h2>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 Django<\/h2>\n<details class=\"spoiler\">\n<summary>\u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0435\u043a\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p><code>python -m venv venv<br \/> venv\\Scripts\\activate<br \/> pip install Django<br \/> django-admin startproject core .<br \/> python manage.py startapp app<br \/> python manage.py migrate<br \/> python manage.py createsuperuser<br \/> pip install django-cors-headers<br \/> python manage.py runserver<\/code><\/p>\n<\/div>\n<\/details>\n<p>\u0417\u0430\u043c\u0435\u0442\u044c\u0442\u0435, \u0447\u0442\u043e \u043c\u044b \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0438 <code>django-cors-headers<\/code> \u044d\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043b\u044f \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430\u043c\u0438, \u0442.\u043a Django \u0438 React \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430\u043c\u0438, \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u0440\u0442\u0430\u0445. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 CORS, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432 \u044d\u0442\u043e\u0439 <a href=\"https:\/\/habr.com\/ru\/companies\/macloud\/articles\/553826\/\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0430\u0442\u044c\u0435<\/a>.<\/p>\n<p><strong><em>settings.py<\/em><\/strong><em><br \/><\/em>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438 corsheaders \u0432 <code>INSTALLED_APPS<\/code><\/p>\n<pre><code class=\"python\">INSTALLED_APPS = [   ...   'app',   'corsheaders', ]<\/code><\/pre>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0435 \u0432 <code>MIDDLEWARE<\/code> <code>'corsheaders.middleware.CorsMiddleware':<\/code><\/p>\n<pre><code class=\"python\">MIDDLEWARE = [   'corsheaders.middleware.CorsMiddleware',    ...  ]<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432 \u0434\u043b\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 <code>Set-Cookie<\/code>, \u043f\u043e\u043b\u043d\u044b\u0439 \u043f\u0435\u0440\u0435\u0447\u0435\u043d\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c <a href=\"https:\/\/developer.mozilla.org\/ru\/docs\/Web\/HTTP\/Headers\/Set-Cookie#%D0%B4%D0%B8%D1%80%D0%B5%D0%BA%D1%82%D0%B8%D0%B2%D1%8B\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<pre><code class=\"python\"># \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 Django \u0438 React - \u0440\u0430\u0437\u043d\u044b\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438, \u0441\u0442\u0430\u0432\u0438\u043c Lax CSRF_COOKIE_SAMESITE = 'Lax' SESSION_COOKIE_SAMESITE = 'Lax'  # \u0427\u0442\u043e\u0431\u044b cookie \u043d\u0435 \u0431\u044b\u043b\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0438\u0437 JS, \u043d\u0443\u0436\u0435\u043d \u0430\u0442\u0440\u0438\u0431\u0443\u0442 HttpOnly CSRF_COOKIE_HTTPONLY = True SESSION_COOKIE_HTTPONLY = True  # \u0414\u043e\u043c\u0435\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u044b \u0434\u043e\u0432\u0435\u0440\u044f\u0435\u043c CSRF_TRUSTED_ORIGINS = ['http:\/\/localhost:3000']  # \u041a\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0437\u0430\u0438\u043c\u0435\u0435\u0442 production \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u0438 https \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 #CSRF_COOKIE_SECURE = True #SESSION_COOKIE_SECURE = True  # \u0412\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u0441\u0435\u0441\u0441\u0438\u0438 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 2 \u043d\u0435\u0434\u0435\u043b\u0438 = 1209600 #SESSION_COOKIE_AGE = 120 &lt;- \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 120 \u0441\u0435\u043a\u0443\u043d\u0434  # \u0427\u0442\u043e\u0431\u044b \u0443\u0431\u0438\u0432\u0430\u0442\u044c \u0441\u0435\u0441\u0441\u0438\u044e \u043f\u0440\u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0438 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430 #SESSION_EXPIRE_AT_BROWSER_CLOSE = True  # \u0420\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u043c\u0435\u0436\u0441\u0430\u0439\u0442\u043e\u0432\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0434\u043b\u044f \u0434\u043e\u043c\u0435\u043d\u0430, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f React \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 CORS_ALLOWED_ORIGINS = [   'http:\/\/localhost:3000',   'http:\/\/127.0.0.1:3000',  ]  # \u0420\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0434\u043b\u044f \u043c\u0435\u0436\u0441\u0430\u0439\u0442\u043e\u0432\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 CORS_EXPOSE_HEADERS = ['Content-Type', 'X-CSRFToken']  # \u0420\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c cookie \u043f\u0440\u0438 \u043c\u0435\u0436\u0441\u0430\u0439\u0442\u043e\u0432\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445 \u043d\u0430 \u0440\u0430\u0437\u0440\u0435\u0448\u0451\u043d\u043d\u044b\u0435 \u0434\u043e\u043c\u0435\u043d\u044b: CORS_ALLOW_CREDENTIALS = True<\/code><\/pre>\n<p><strong><em>core\/urls.py:<\/em><\/strong><\/p>\n<pre><code class=\"python\">from django.contrib import admin from django.urls import path, include  urlpatterns = [    path('admin\/', admin.site.urls),    path('api\/', include('app.urls')) ]<\/code><\/pre>\n<p><strong><em>app\/urls.py<\/em><\/strong><\/p>\n<pre><code class=\"python\">from django.urls import path from . import views  urlpatterns = [    path('csrf\/', views.get_csrf, name='api-csrf'),    path('login\/', views.login_view, name='api-login'),    path('logout\/', views.logout_view, name='api-logout'),    path('session\/', views.session_view, name='api-session'),    path('user_info\/', views.user_info, name='api-userInfo'),    path('kill_all_sessions\/', views.kill_all_sessions, name='kill-all-sessions'), ]<\/code><\/pre>\n<p><strong><em>app\/views.py<\/em><\/strong><\/p>\n<pre><code class=\"python\">import json from django.contrib.auth import authenticate, login, logout from django.http import JsonResponse from django.middleware.csrf import get_token from django.views.decorators.csrf import ensure_csrf_cookie from django.views.decorators.http import require_POST from django.contrib.sessions.models import Session  # \u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u0432\u044b\u0434\u0430\u0447\u0438 \u043e\u0448\u0438\u0431\u043a\u0438 \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435\u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d def json_login_required(view_func):     def wrapped_view(request, *args, **kwargs):         if not request.user.is_authenticated:             return JsonResponse({'error': '\u0412\u044b \u043d\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u044b'}, status=401)         return view_func(request, *args, **kwargs)     return wrapped_view<\/code><\/pre>\n<p>\u0411\u044b\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u0441\u0430\u043c\u043e\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 <code>@login_required <\/code>\u0434\u0435\u043b\u0430\u043b \u0440\u0435\u0434\u0438\u0440\u0435\u043a\u0442 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u043b\u0438 \u044e\u0437\u0435\u0440 \u043d\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d, \u043c\u043d\u0435 \u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043a\u0438\u0434\u0430\u0442\u044c \u043d\u0430 \u043a\u043b\u0438\u0435\u043d\u0442 \u043e\u0448\u0438\u0431\u043a\u0443. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u0430\u043a-\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u043f\u043e-\u0443\u043c\u043d\u043e\u043c\u0443 \u0438 \u043d\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434, \u0431\u0443\u0434\u0443 \u0440\u0430\u0434 \u043f\u043e\u043f\u0440\u0430\u0432\u043a\u0430\u043c. \u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043d\u0435\u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c (\u043f\u0440\u043e\u0444\u0438\u043b\u044c, \u043a\u043e\u0440\u0437\u0438\u043d\u0430 \u0438 \u0442.\u043f)<\/p>\n<pre><code class=\"python\"># \u0421\u043e\u0437\u0434\u0430\u0451\u0442 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 CSRF-\u0442\u043e\u043a\u0435\u043d \u0438 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0432 cookie \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0443 def get_csrf(request):     response = JsonResponse({'detail': 'CSRF cookie set'})     response['X-CSRFToken'] = get_token(request)     return response<\/code><\/pre>\n<p>\u041f\u0440\u0438 &#171;\u043e\u043f\u0430\u0441\u043d\u044b\u0445&#187; \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u0434\u0434\u0435\u043b\u0430\u0442\u044c\u0441\u044f \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u043e\u043c, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f. \u041a\u043b\u0438\u0435\u043d\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0438\u0442\u044c \u044d\u0442\u043e\u0442 CSRF-\u0442\u043e\u043a\u0435\u043d<\/p>\n<pre><code class=\"python\">@require_POST def login_view(request):     # \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435     data = json.loads(request.body)     username = data.get('username')     password = data.get('password')      # \u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f     if username is None or password is None:         return JsonResponse({'detail': '\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u043b\u043e\u0433\u0438\u043d \u0438 \u043f\u0430\u0440\u043e\u043b\u044c'}, status=400)      # \u0410\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u044f     user = authenticate(username=username, password=password)          if user is None:         return JsonResponse({'detail': '\u041d\u0435\u0432\u0435\u0440\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435'}, status=400)      # \u0421\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0441\u0435\u0441\u0441\u0438\u044f. session_id \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u043a\u0443\u043a\u0438     login(request, user)     return JsonResponse({'detail': '\u0423\u0441\u043f\u0435\u0448\u043d\u0430\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f'})     # \u0421\u0435\u0441\u0441\u0438\u044f \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0437 \u0411\u0414 \u0438 session_id \u043d\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0435 \u0431\u043e\u043b\u0435\u0435 \u043d\u0435\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u0435\u043d @json_login_required def logout_view(request):     logout(request)     return JsonResponse({'detail': '\u0412\u044b \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0432\u044b\u0448\u043b\u0438'})     # \u0423\u0437\u043d\u0430\u0442\u044c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d \u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0435\u0433\u043e \u0434\u0430\u043d\u043d\u044b\u0435 @ensure_csrf_cookie # &lt;- \u041f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 CSRF cookie def session_view(request):     if not request.user.is_authenticated:         return JsonResponse({'isAuthenticated': False})      return JsonResponse({'isAuthenticated': True, 'username': request.user.username, 'user_id': request.user.id})     # \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435 @json_login_required def user_info(request):     return JsonResponse({'username': request.user.username})     # \u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0441\u0435\u0441\u0441\u0438\u0439 \u0438\u0437 \u0411\u0414 # \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u0435\u0441\u0441\u0438\u044e \u0443 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f @json_login_required def kill_all_sessions(request):     sessions = Session.objects.all()     sessions.delete()      return JsonResponse({'detail': '\u0421\u0435\u0441\u0441\u0438\u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u044b'})<\/code><\/pre>\n<h2>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 React<\/h2>\n<p>\u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 <a href=\"https:\/\/create-react-app.dev\/docs\/getting-started\/\" rel=\"noopener noreferrer nofollow\">CRA<\/a>. \u0414\u0430\u043b\u0435\u0435 <code>npm install axios<\/code><\/p>\n<pre><code class=\"typescript\">import React, { useState, useEffect } from \"react\"; import axios from 'axios';  import style from '.\/index.module.scss';   \/\/ \u0412\u0430\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c http:\/\/127.0.0.1:8000 cookie \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f const serverUrl = 'http:\/\/localhost:8000\/'  const Form = () => {     const [isCsrf, setIsCsrf] = useState(null)     const [isLogin, setIsLogin] = useState('')     const [isPassword, setIsPassword] = useState('')     const [isError, setIsError] = useState(null)     const [isAuth, setIsAuth] = useState(false)     const [username, setUsername] = useState('')     const [userId, setUserId] = useState(null)      \/\/ \u041f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u043c\u044b \u0441\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c, \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d \u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c     useEffect(() => {         getSession()     }, [])      const isResponseOk = (res) => {       if (!(res.status >= 200 &amp;&amp; res.status &lt;= 299)) {         throw Error(res.statusText);       }     }      \/\/ \u0415\u0441\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f, \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c CSRF-\u0442\u043e\u043a\u0435\u043d \u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0430     const getCSRF = () => {         axios.get(serverUrl + 'api\/csrf\/', { withCredentials: true })         .then((res) => {             isResponseOk(res)              const csrfToken = res.headers.get('X-CSRFToken')             setIsCsrf(csrfToken)         })         .catch((err) => console.error(err))     }      \/\/ withCredentials:true - \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u044f \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b credentials='include'     const getSession = () => {       axios.get(serverUrl + \"api\/session\/\", { withCredentials: true })       .then((res) => {           if (res.data.isAuthenticated) {               setUserId(res.data.user_id)               setUsername(res.data.username)               setIsAuth(true)               return           }            setIsAuth(false)           getCSRF()       })       .catch(err => console.error(err))     }      \/\/ \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 CSRF-\u0442\u043e\u043a\u0435\u043d \u043f\u0438\u0445\u0430\u0435\u043c \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0443     const login = () => {       const data = { username: isLogin, password: isPassword }       axios.post(serverUrl + \"api\/login\/\", data, {         withCredentials: true,         headers: {           \"Content-Type\": \"application\/json\",           \"X-CSRFToken\": isCsrf,         }       })       .then((res) => {         isResponseOk(res)         setIsAuth(true)         setIsLogin('')         setIsPassword('')         setIsError(null)                  userInfo()       })       .catch((err) => {         console.error(err);         setIsError(\"\u041d\u0435\u0432\u0435\u0440\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435\")       });     }      const logout = () => {       axios.get(serverUrl + \"api\/logout\", { withCredentials: true })       .then((res) => {         isResponseOk(res)         setIsAuth(false);         getCSRF();       })       .catch(err => console.error(err));     }      const userInfo = () => {       axios.get(serverUrl + \"api\/user_info\/\", {         withCredentials: true,         headers: {           \"Content-Type\": \"application\/json\",         },       })       .then((res) => {         console.log(\"\u0412\u044b \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u043a\u0430\u043a: \" + res.data.username);         setUsername(res.data.username)       })       .catch((err) => {           if (err.status === 401) console.log(err.error);       });     }      const killAllSessions = () => {       axios.get(serverUrl + \"api\/kill_all_sessions\/\", {         withCredentials: true,         headers: {           \"Content-Type\": \"application\/json\",         },       })       .then((res) => {         isResponseOk(res)         console.log(res.data.detail)       })       .catch((err) => {         console.log(err);       });     }      function changePassword(e) {         setIsPassword(e.target.value)     }      function changeLogin(e) {         setIsLogin(e.target.value)     }      function submitForm(e) {         e.preventDefault()         login()     }      return(       &lt;div className={style.container}>           &lt;div className={style.authStatus}>             \u0412\u044b -              &lt;span className={style.username}>             {               isAuth ? ' ' + username   : ' \u043d\u0435\u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u044b'              }             &lt;\/span>           &lt;\/div>            {             !isAuth ?               &lt;form className={style.formContainer}>                   &lt;label htmlFor=\"login\">\u041b\u043e\u0433\u0438\u043d&lt;\/label>                   &lt;input                        type=\"text\"                        name=\"login\"                        id=\"login\"                        className={style.field}                       onChange={changeLogin}                       value={isLogin}                   \/>                    &lt;label htmlFor=\"password\">\u041f\u0430\u0440\u043e\u043b\u044c&lt;\/label>                   &lt;input                        type=\"password\"                        name=\"password\"                        id=\"password\"                        className={style.field}                        onChange={changePassword}                       value={isPassword}                   \/>                    {                       isError ? &lt;div className={style.error}>{isError}&lt;\/div> : null                   }                    &lt;input type=\"submit\" value='\u0412\u043e\u0439\u0442\u0438' onClick={submitForm} className={style.sendBtn} \/>               &lt;\/form>             :                &lt;div className={style.btnContainer}>                   &lt;input type=\"submit\" value='\u0412\u044b\u0439\u0442\u0438' onClick={logout} className={style.logoutBtn} \/>                   &lt;input type=\"submit\" value='\u0423\u0431\u0438\u0442\u044c \u0432\u0441\u0435 \u0441\u0435\u0441\u0441\u0438\u0438' onClick={killAllSessions} className={style.killAllSessionsBtn} \/>               &lt;\/div>                              }       &lt;\/div>     ) }  export default Form;<\/code><\/pre>\n<p>\u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, React \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0437\u0435\u0440\u043a\u0430\u043b\u0438\u0442 Django. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0443\u0431\u0435\u0436\u0434\u0430\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u043c\u044b \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u044b, \u0435\u0441\u043b\u0438 \u043d\u0435\u0442, \u0442\u043e \u043f\u0440\u043e\u0441\u0438\u043c CSRF-\u0442\u043e\u043a\u0435\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435 \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0444\u043e\u0440\u043c\u044b \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440. \u041a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u0433\u0434\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u044b\u0442\u044c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u043c, \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>withCredentials:true<\/code>, \u0447\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0451\u0442 \u043d\u0430\u0448 session_id \u0438 CSRF-\u0442\u043e\u043a\u0435\u043d, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044f \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440, \u0433\u0434\u0435 \u043e\u043d, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u0442 session_id \u043f\u043e \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u043c\u043e\u0434\u0435\u043b\u0438 Session.<\/p>\n<h2>\u0418\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430<\/h2>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0432\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0445\u043e\u0434\u0438\u0442\u0435 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0432 DevTools \u0432\u043e \u0432\u043a\u043b\u0430\u0434\u043a\u0435 Network \u043f\u043e\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u0434\u0432\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430: session \u0438 csrf, \u0435\u0441\u043b\u0438 \u0431\u044b \u0432\u044b \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0431\u044b\u043b\u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u044b, \u0442\u043e \u043f\u043e\u0441\u043b\u0430\u043b\u0441\u044f \u0431\u044b \u043b\u0438\u0448\u044c session. \u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u043b\u043e\u0433\u0438\u043d \u0438 \u043f\u0430\u0440\u043e\u043b\u044c \u0441\u0443\u043f\u0435\u0440\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f Django, \u0435\u0441\u043b\u0438 \u0432\u0441\u0451 \u0432\u0435\u0440\u043d\u043e, \u0442\u043e \u043f\u043e\u044f\u0432\u044f\u0442\u0441\u044f \u0435\u0449\u0451 \u0434\u0432\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 login \u0438 user_info, \u0430 \u0432\u043e \u0432\u043a\u043b\u0430\u0434\u043a\u0435 applications -> cookies \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f sessionid.<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u0435\u0441\u0441\u0438\u0439 \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0438 \u043f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b, \u0440\u0430\u043d\u044c\u0448\u0435 \u043c\u043d\u043e\u0433\u0438\u0435 \u0441\u0435\u0442\u043e\u0432\u0430\u043b\u0438 \u043d\u0430 \u0435\u0451 \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c, \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0441 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 cookies \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430\u0445. \u041e\u0434\u043d\u0430\u043a\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u044d\u0442\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043b\u0438 \u0441\u0442\u043e\u044f\u0442\u044c \u0442\u0430\u043a \u043e\u0441\u0442\u0440\u043e \u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u0435\u0441\u0441\u0438\u0439, \u043f\u043e-\u043c\u043e\u0435\u043c\u0443 \u043c\u043d\u0435\u043d\u0438\u044e, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u0435\u0440\u0441\u043f\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439<\/p>\n<p><a href=\"https:\/\/github.com\/\" rel=\"noopener noreferrer nofollow\">\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/a><\/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\/804615\/\"> https:\/\/habr.com\/ru\/articles\/804615\/<\/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\u0435\u043c \u0437\u0434\u0440\u0430\u0432\u0438\u044f! \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0435\u0441\u0441\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 Django \u0438 React, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0445\u0441\u044f \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0434\u043e\u043c\u0435\u043d\u0430\u0445, \u0442.\u0435 \u0441\u043b\u0443\u0447\u0430\u0439 &#171;cross-origin&#187;. \u042f \u0432 \u0434\u0432\u0443\u0445 \u0441\u043b\u043e\u0432\u0430\u0445 \u0434\u043e\u043d\u0435\u0441\u0443 \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0430\u0431\u043e\u0442\u044b, \u043f\u0440\u0438\u0447\u0438\u043d\u044b \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0439 \u0438 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0439, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u0437\u0434\u0435\u0441\u044c, \u043e\u0441\u0442\u0430\u0432\u043b\u044e \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438 \u0438 \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043a\u043e\u0434 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435\u043c \u0441\u0432\u043e\u0438\u0445 \u0448\u0430\u0433\u043e\u0432. \u041a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 &#8212; \u043e\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430 <a href=\"https:\/\/github.com\/VlassaDassa\/django-react-cookie-auth\" rel=\"noopener noreferrer nofollow\">GitHub<\/a>.<\/p>\n<h2>\u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0435\u0441\u0441\u0438\u0439<\/h2>\n<p>\u041a\u0430\u043a \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432\u0432\u043e\u0434\u0438\u0442 \u0434\u0430\u043d\u043d\u044b\u0435, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440;<\/p>\n<\/li>\n<li>\n<p>\u0421\u0435\u0440\u0432\u0435\u0440 \u0438\u0445 \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u0442, \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0441\u0435\u0441\u0441\u0438\u044e, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 cookie \u0438 \u043e\u0442\u0441\u044b\u043b\u0430\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e session_id. \u0421\u0435\u0440\u0432\u0435\u0440 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a <code>Set-Cookie: session_id=id<\/code><\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043a\u043b\u0438\u0435\u043d\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043e\u0442\u0432\u0435\u0442, \u0432 \u0435\u0433\u043e cookie \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 Set-Cookie \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f ID \u0441\u0435\u0441\u0441\u0438\u0438<\/p>\n<\/li>\n<li>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043a \u0441\u0435\u0440\u0432\u0435\u0440\u0443, \u043a\u043b\u0438\u0435\u043d\u0442 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0432\u0441\u0435 \u0441\u0432\u043e\u0438 cookies, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0435\u0441\u0442\u044c session_id. \u0421\u0435\u0440\u0432\u0435\u0440 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0435\u0441\u0442\u044c \u043b\u0438 \u044d\u0442\u0430 \u0441\u0435\u0441\u0441\u0438\u044f, \u0436\u0438\u0432\u0430 \u043b\u0438 \u043e\u043d\u0430 \u0438 \u0434\u0430\u0451\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u043c<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u0438\u0437 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0441\u0435\u0441\u0441\u0438\u044f \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f \u0438 \u043d\u044b\u043d\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0439\u0441\u044f id \u0441\u0435\u0441\u0441\u0438\u0438 \u0443\u0436\u0435 \u043d\u0435\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u0435\u043d \u0438 \u043f\u0440\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445, \u044e\u0437\u0435\u0440\u0443 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043a\u0430\u0437\u0430\u043d\u043e \u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u0435<\/p>\n<\/li>\n<\/ul>\n<h2>\u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430<\/h2>\n<p>\u041d\u0430 \u043f\u0443\u0442\u0438 \u0441\u0435\u0441\u0441\u0438\u0438 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 CSRF-\u0430\u0442\u0430\u043a\u0438, \u043f\u0443\u0433\u0430\u044e\u0449\u0438\u0435 \u0441\u0432\u043e\u0435\u0439 \u0438\u0437\u043e\u0449\u0440\u0451\u043d\u043d\u043e\u0441\u0442\u044c\u044e \u0438 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e\u043c cookies, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0442\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0434\u043e\u043c\u0435\u043d, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u043d\u0438 \u0431\u044b\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u044b. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0438\u0437 \u044d\u0442\u043e\u0439 <a href=\"https:\/\/habr.com\/ru\/companies\/oleg-bunin\/articles\/412855\/\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0430\u0442\u044c\u0438<\/a>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u0441\u043c\u044b\u0441\u043b \u044d\u0442\u0438\u0445 \u0430\u0442\u0430\u043a \u0438 \u043a\u0430\u043a \u043e\u0442 \u043d\u0438\u0445 \u0437\u0430\u0449\u0438\u0449\u0430\u0442\u044c\u0441\u044f, \u043d\u043e \u0443\u0432\u0435\u0440\u0435\u043d, \u0447\u0442\u043e \u0434\u043e\u0447\u0438\u0442\u0430\u0435\u0442\u0435 \u0434\u043e \u043a\u043e\u043d\u0446\u0430, \u0432\u0435\u0434\u044c \u044d\u0442\u043e \u0432\u0435\u0441\u044c\u043c\u0430 \u043b\u044e\u0431\u043e\u043f\u044b\u0442\u043d\u043e.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043a\u0440\u0430\u0442\u043a\u043e \u043e\u0431 CSRF-\u0443\u044f\u0437\u0432\u0438\u043c\u043e\u0441\u0442\u0438: \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0430 \u0432\u0430\u0441 \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u043e\u0431\u0440\u0430\u0437\u043e\u043c &#171;\u0440\u0435\u0434\u0438\u0440\u0435\u043a\u0442\u044f\u0442&#187; \u043d\u0430 \u0442\u043e\u0442 \u0434\u043e\u043c\u0435\u043d, \u0433\u0434\u0435 \u0432\u044b, \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043c\u043e\u0436\u0435\u0442\u0435 \u0431\u044b\u0442\u044c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u0438 \u0433\u0434\u0435 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0435 \u0441\u0430\u043c\u044b\u0435 cookie. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 cookie \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0430 \u0434\u043e\u043c\u0435\u043d, \u0442\u043e \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u0440\u043e\u0439\u0434\u0451\u0442 \u043a\u0430\u043a \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439. \u0422.\u0435 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a \u0441\u043c\u043e\u0436\u0435\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043e\u0442 \u0432\u0430\u0448\u0435\u0433\u043e \u043b\u0438\u0446\u0430.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u043b\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 CSRF-\u0442\u043e\u043a\u0435\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u043e\u0440\u0430\u0437\u043e\u0432\u044b\u043c. \u041f\u0440\u0438 \u043e\u043f\u0430\u0441\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u0445, \u0433\u0434\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0442\u043e\u0442 \u0437\u0430 \u043a\u043e\u0433\u043e \u0441\u0435\u0431\u044f \u0432\u044b\u0434\u0430\u0451\u0442 (POST, DELETE \u0438 \u0442.\u043f), \u0435\u043c\u0443 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f CSRF-\u0442\u043e\u043a\u0435\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043d \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442 \u0432 cookie \u0432\u043c\u0435\u0441\u0442\u0435 \u0441\u043e \u0441\u0432\u043e\u0438\u043c \u043e\u043f\u0430\u0441\u043d\u044b\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c. \u041d\u0430 \u0441\u0430\u0439\u0442\u0435 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0430 \u0431\u044b \u0442\u0430\u043a\u043e\u0435 \u043d\u0435 \u043f\u0440\u043e\u043a\u0430\u0442\u0438\u043b\u043e, \u0435\u043c\u0443 \u0431\u044b \u043d\u0438\u043a\u0442\u043e \u043f\u043e\u043f\u0440\u043e\u0441\u0442\u0443 \u043d\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043b \u044d\u0442\u043e\u0442 \u0442\u043e\u043a\u0435\u043d. \u042d\u0442\u043e \u043b\u0438\u0448\u044c \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0437\u0430\u0449\u0438\u0442\u044b.<\/p>\n<h2>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 Django<\/h2>\n<details class=\"spoiler\">\n<summary>\u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0435\u043a\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p><code>python -m venv venv<br \/> venv\\Scripts\\activate<br \/> pip install Django<br \/> django-admin startproject core .<br \/> python manage.py startapp app<br \/> python manage.py migrate<br \/> python manage.py createsuperuser<br \/> pip install django-cors-headers<br \/> python manage.py runserver<\/code><\/p>\n<\/div>\n<\/details>\n<p>\u0417\u0430\u043c\u0435\u0442\u044c\u0442\u0435, \u0447\u0442\u043e \u043c\u044b \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0438 <code>django-cors-headers<\/code> \u044d\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043b\u044f \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430\u043c\u0438, \u0442.\u043a Django \u0438 React \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430\u043c\u0438, \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u0440\u0442\u0430\u0445. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 CORS, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432 \u044d\u0442\u043e\u0439 <a href=\"https:\/\/habr.com\/ru\/companies\/macloud\/articles\/553826\/\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0430\u0442\u044c\u0435<\/a>.<\/p>\n<p><strong><em>settings.py<\/em><\/strong><em><br \/><\/em>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438 corsheaders \u0432 <code>INSTALLED_APPS<\/code><\/p>\n<pre><code class=\"python\">INSTALLED_APPS = [   ...   'app',   'corsheaders', ]<\/code><\/pre>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0435 \u0432 <code>MIDDLEWARE<\/code> <code>'corsheaders.middleware.CorsMiddleware':<\/code><\/p>\n<pre><code class=\"python\">MIDDLEWARE = [   'corsheaders.middleware.CorsMiddleware',    ...  ]<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432 \u0434\u043b\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 <code>Set-Cookie<\/code>, \u043f\u043e\u043b\u043d\u044b\u0439 \u043f\u0435\u0440\u0435\u0447\u0435\u043d\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c <a href=\"https:\/\/developer.mozilla.org\/ru\/docs\/Web\/HTTP\/Headers\/Set-Cookie#%D0%B4%D0%B8%D1%80%D0%B5%D0%BA%D1%82%D0%B8%D0%B2%D1%8B\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<pre><code class=\"python\"># \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 Django \u0438 React - \u0440\u0430\u0437\u043d\u044b\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438, \u0441\u0442\u0430\u0432\u0438\u043c Lax CSRF_COOKIE_SAMESITE = 'Lax' SESSION_COOKIE_SAMESITE = 'Lax'  # \u0427\u0442\u043e\u0431\u044b cookie \u043d\u0435 \u0431\u044b\u043b\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0438\u0437 JS, \u043d\u0443\u0436\u0435\u043d \u0430\u0442\u0440\u0438\u0431\u0443\u0442 HttpOnly CSRF_COOKIE_HTTPONLY = True SESSION_COOKIE_HTTPONLY = True  # \u0414\u043e\u043c\u0435\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u044b \u0434\u043e\u0432\u0435\u0440\u044f\u0435\u043c CSRF_TRUSTED_ORIGINS = ['http:\/\/localhost:3000']  # \u041a\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0437\u0430\u0438\u043c\u0435\u0435\u0442 production \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u0438 https \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 #CSRF_COOKIE_SECURE = True #SESSION_COOKIE_SECURE = True  # \u0412\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u0441\u0435\u0441\u0441\u0438\u0438 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 2 \u043d\u0435\u0434\u0435\u043b\u0438 = 1209600 #SESSION_COOKIE_AGE = 120 &lt;- \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 120 \u0441\u0435\u043a\u0443\u043d\u0434  # \u0427\u0442\u043e\u0431\u044b \u0443\u0431\u0438\u0432\u0430\u0442\u044c \u0441\u0435\u0441\u0441\u0438\u044e \u043f\u0440\u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0438 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430 #SESSION_EXPIRE_AT_BROWSER_CLOSE = True  # \u0420\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u043c\u0435\u0436\u0441\u0430\u0439\u0442\u043e\u0432\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0434\u043b\u044f \u0434\u043e\u043c\u0435\u043d\u0430, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f React \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 CORS_ALLOWED_ORIGINS = [   'http:\/\/localhost:3000',   'http:\/\/127.0.0.1:3000',  ]  # \u0420\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0434\u043b\u044f \u043c\u0435\u0436\u0441\u0430\u0439\u0442\u043e\u0432\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 CORS_EXPOSE_HEADERS = ['Content-Type', 'X-CSRFToken']  # \u0420\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c cookie \u043f\u0440\u0438 \u043c\u0435\u0436\u0441\u0430\u0439\u0442\u043e\u0432\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445 \u043d\u0430 \u0440\u0430\u0437\u0440\u0435\u0448\u0451\u043d\u043d\u044b\u0435 \u0434\u043e\u043c\u0435\u043d\u044b: CORS_ALLOW_CREDENTIALS = True<\/code><\/pre>\n<p><strong><em>core\/urls.py:<\/em><\/strong><\/p>\n<pre><code class=\"python\">from django.contrib import admin from django.urls import path, include  urlpatterns = [    path('admin\/', admin.site.urls),    path('api\/', include('app.urls')) ]<\/code><\/pre>\n<p><strong><em>app\/urls.py<\/em><\/strong><\/p>\n<pre><code class=\"python\">from django.urls import path from . import views  urlpatterns = [    path('csrf\/', views.get_csrf, name='api-csrf'),    path('login\/', views.login_view, name='api-login'),    path('logout\/', views.logout_view, name='api-logout'),    path('session\/', views.session_view, name='api-session'),    path('user_info\/', views.user_info, name='api-userInfo'),    path('kill_all_sessions\/', views.kill_all_sessions, name='kill-all-sessions'), ]<\/code><\/pre>\n<p><strong><em>app\/views.py<\/em><\/strong><\/p>\n<pre><code class=\"python\">import json from django.contrib.auth import authenticate, login, logout from django.http import JsonResponse from django.middleware.csrf import get_token from django.views.decorators.csrf import ensure_csrf_cookie from django.views.decorators.http import require_POST from django.contrib.sessions.models import Session  # \u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u0432\u044b\u0434\u0430\u0447\u0438 \u043e\u0448\u0438\u0431\u043a\u0438 \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435\u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d def json_login_required(view_func):     def wrapped_view(request, *args, **kwargs):         if not request.user.is_authenticated:             return JsonResponse({'error': '\u0412\u044b \u043d\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u044b'}, status=401)         return view_func(request, *args, **kwargs)     return wrapped_view<\/code><\/pre>\n<p>\u0411\u044b\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u0441\u0430\u043c\u043e\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 <code>@login_required <\/code>\u0434\u0435\u043b\u0430\u043b \u0440\u0435\u0434\u0438\u0440\u0435\u043a\u0442 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u043b\u0438 \u044e\u0437\u0435\u0440 \u043d\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d, \u043c\u043d\u0435 \u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043a\u0438\u0434\u0430\u0442\u044c \u043d\u0430 \u043a\u043b\u0438\u0435\u043d\u0442 \u043e\u0448\u0438\u0431\u043a\u0443. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u0430\u043a-\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u043f\u043e-\u0443\u043c\u043d\u043e\u043c\u0443 \u0438 \u043d\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434, \u0431\u0443\u0434\u0443 \u0440\u0430\u0434 \u043f\u043e\u043f\u0440\u0430\u0432\u043a\u0430\u043c. \u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043d\u0435\u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c (\u043f\u0440\u043e\u0444\u0438\u043b\u044c, \u043a\u043e\u0440\u0437\u0438\u043d\u0430 \u0438 \u0442.\u043f)<\/p>\n<pre><code class=\"python\"># \u0421\u043e\u0437\u0434\u0430\u0451\u0442 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 CSRF-\u0442\u043e\u043a\u0435\u043d \u0438 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0432 cookie \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0443 def get_csrf(request):     response = JsonResponse({'detail': 'CSRF cookie set'})     response['X-CSRFToken'] = get_token(request)     return response<\/code><\/pre>\n<p>\u041f\u0440\u0438 &#171;\u043e\u043f\u0430\u0441\u043d\u044b\u0445&#187; \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u0434\u0434\u0435\u043b\u0430\u0442\u044c\u0441\u044f \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u043e\u043c, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f. \u041a\u043b\u0438\u0435\u043d\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0438\u0442\u044c \u044d\u0442\u043e\u0442 CSRF-\u0442\u043e\u043a\u0435\u043d<\/p>\n<pre><code class=\"python\">@require_POST def login_view(request):     # \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435     data = json.loads(request.body)     username = data.get('username')     password = data.get('password')      # \u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f     if username is None or password is None:         return JsonResponse({'detail': '\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u043b\u043e\u0433\u0438\u043d \u0438 \u043f\u0430\u0440\u043e\u043b\u044c'}, status=400)      # \u0410\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u044f     user = authenticate(username=username, password=password)          if user is None:         return JsonResponse({'detail': '\u041d\u0435\u0432\u0435\u0440\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435'}, status=400)      # \u0421\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0441\u0435\u0441\u0441\u0438\u044f. session_id \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u043a\u0443\u043a\u0438     login(request, user)     return JsonResponse({'detail': '\u0423\u0441\u043f\u0435\u0448\u043d\u0430\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f'})     # \u0421\u0435\u0441\u0441\u0438\u044f \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0437 \u0411\u0414 \u0438 session_id \u043d\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0435 \u0431\u043e\u043b\u0435\u0435 \u043d\u0435\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u0435\u043d @json_login_required def logout_view(request):     logout(request)     return JsonResponse({'detail': '\u0412\u044b \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0432\u044b\u0448\u043b\u0438'})     # \u0423\u0437\u043d\u0430\u0442\u044c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d \u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0435\u0433\u043e \u0434\u0430\u043d\u043d\u044b\u0435 @ensure_csrf_cookie # &lt;- \u041f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 CSRF cookie def session_view(request):     if not request.user.is_authenticated:         return JsonResponse({'isAuthenticated': False})      return JsonResponse({'isAuthenticated': True, 'username': request.user.username, 'user_id': request.user.id})     # \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435 @json_login_required def user_info(request):     return JsonResponse({'username': request.user.username})     # \u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0441\u0435\u0441\u0441\u0438\u0439 \u0438\u0437 \u0411\u0414 # \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u0435\u0441\u0441\u0438\u044e \u0443 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f @json_login_required def kill_all_sessions(request):     sessions = Session.objects.all()     sessions.delete()      return JsonResponse({'detail': '\u0421\u0435\u0441\u0441\u0438\u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u044b'})<\/code><\/pre>\n<h2>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 React<\/h2>\n<p>\u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 <a href=\"https:\/\/create-react-app.dev\/docs\/getting-started\/\" rel=\"noopener noreferrer nofollow\">CRA<\/a>. \u0414\u0430\u043b\u0435\u0435 <code>npm install axios<\/code><\/p>\n<pre><code class=\"typescript\">import React, { useState, useEffect } from \"react\"; import axios from 'axios';  import style from '.\/index.module.scss';   \/\/ \u0412\u0430\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c http:\/\/127.0.0.1:8000 cookie \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f const serverUrl = 'http:\/\/localhost:8000\/'  const Form = () => {     const [isCsrf, setIsCsrf] = useState(null)     const [isLogin, setIsLogin] = useState('')     const [isPassword, setIsPassword] = useState('')     const [isError, setIsError] = useState(null)     const [isAuth, setIsAuth] = useState(false)     const [username, setUsername] = useState('')     const [userId, setUserId] = useState(null)      \/\/ \u041f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u043c\u044b \u0441\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c, \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d \u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c     useEffect(() => {         getSession()     }, [])      const isResponseOk = (res) => {       if (!(res.status >= 200 &amp;&amp; res.status &lt;= 299)) {         throw Error(res.statusText);       }     }      \/\/ \u0415\u0441\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f, \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c CSRF-\u0442\u043e\u043a\u0435\u043d \u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0430     const getCSRF = () => {         axios.get(serverUrl + 'api\/csrf\/', { withCredentials: true })         .then((res) => {             isResponseOk(res)              const csrfToken = res.headers.get('X-CSRFToken')             setIsCsrf(csrfToken)         })         .catch((err) => console.error(err))     }      \/\/ withCredentials:true - \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u044f \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b credentials='include'     const getSession = () => {       axios.get(serverUrl + \"api\/session\/\", { withCredentials: true })       .then((res) => {           if (res.data.isAuthenticated) {               setUserId(res.data.user_id)               setUsername(res.data.username)               setIsAuth(true)               return           }            setIsAuth(false)           getCSRF()       })       .catch(err => console.error(err))     }      \/\/ \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 CSRF-\u0442\u043e\u043a\u0435\u043d \u043f\u0438\u0445\u0430\u0435\u043c \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0443     const login = () => {       const data = {<\/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-372463","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/372463","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=372463"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/372463\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=372463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=372463"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=372463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}