{"id":348166,"date":"2023-05-31T15:01:19","date_gmt":"2023-05-31T15:01:19","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=348166"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=348166","title":{"rendered":"<span>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0431\u043b\u043e\u0433 \u043d\u0430 Django \u0441 \u043e\u043f\u0440\u043e\u0441\u0430\u043c\u0438 \u0438 \u0442\u0435\u0441\u0442\u0430\u043c\u0438. \u041a\u0440\u0430\u0442\u043a\u0430\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f. \u0427\u0430\u0441\u0442\u044c 2<\/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-1\">\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/a1\/k3\/fy\/a1k3fytzay17q3bya7b5dcaal80.png\"><\/div>\n<p>  \u0412 <a href=\"https:\/\/habr.com\/ru\/companies\/selectel\/articles\/735556\/\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438<\/a> \u043c\u044b \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438 \u0448\u0430\u0431\u043b\u043e\u043d \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0431\u043b\u043e\u0433\u0430, \u0432\u044b\u0431\u0440\u0430\u043b\u0438 <a href=\"https:\/\/selectel.ru\/services\/cloud\/servers\/?utm_source=habr.com&amp;utm_medium=referral&amp;utm_campaign=cloud_article_gjango_310523_content\">\u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u0443\u044e \u043c\u0430\u0448\u0438\u043d\u0443<\/a> \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u043d\u0430 \u043d\u0435\u0439 \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0435\u0440 Django. \u041e\u0434\u043d\u0430\u043a\u043e \u043e\u043d \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u0414\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c Nginx \u0438 WSGI Gunicorn. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c. <br \/>  <a name=\"habracut\"><\/a><br \/>  <font color=\"#EB4247\"><\/p>\n<h2>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u044b\u0435 \u0444\u0438\u0447\u0438<\/h2>\n<p><\/font><br \/>  \u041f\u0435\u0440\u0435\u0434 \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u043c \u0431\u043b\u043e\u0433\u0430 \u0432 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d \u043b\u0443\u0447\u0448\u0435 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430. \u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u0441\u043e\u0431\u0440\u0430\u043b\u0438 \u043b\u0438\u0448\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0435 Django-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u2014 <a href=\"https:\/\/github.com\/natkaida\/blogit\/tree\/main\/users\">users<\/a> \u0438 <a href=\"https:\/\/github.com\/natkaida\/blogit\/tree\/main\/blog\">blog<\/a>. \u041d\u043e \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0438\u0447\u0438 \u043c\u044b \u043f\u043e\u043a\u0430 \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u2014 \u043f\u043e\u0440\u0430 \u044d\u0442\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c.<\/p>\n<p>  \u041d\u0438\u0436\u0435 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u043c \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u0442\u0435\u0441\u0442\u043e\u0432 \u0432 \u0431\u043b\u043e\u0433\u0435 \u043d\u0430 Django. \u0414\u0435\u043b\u0430\u0439\u0442\u0435 <a href=\"https:\/\/github.com\/natkaida\/blogit\">\u0444\u043e\u0440\u043a \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430<\/a>, \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0439\u0442\u0435 \u0438 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0439\u0442\u0435 \u0441\u0432\u043e\u0438 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f!<\/p>\n<h3>\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 polls<\/h3>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/1i\/ud\/iy\/1iudiybpb4ioou3xip1mxut1b5s.png\"><\/div>\n<p>  \u0412 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 <a href=\"https:\/\/github.com\/natkaida\/blogit\/tree\/main\/polls\">polls<\/a> \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0435\u043d\u0430 \u0432\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0430\u044f \u0441 \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u043e\u043f\u0440\u043e\u0441\u043e\u0432. \u0427\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c, \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0439 \u0441\u043a\u0440\u0438\u043f\u0442 manage.py \u0438 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435.<\/p>\n<pre><code class=\"plaintext\">manage.py startapp polls<\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u0432\u0430\u0436\u043d\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435 settings.py.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/2q\/vn\/vi\/2qvnvikl6okcuxsiie5lhxawaig.png\" width=\"350\"><\/div>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043c\u043e\u0433 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e, \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0446\u0438\u044e \u2014 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u0432 \u043a\u043e\u0440\u043d\u0435\u0432\u0443\u044e \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0443\u0442\u0438 \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435 urls.py.<\/p>\n<pre><code class=\"plaintext\">path('', include('polls.urls')) <\/code><\/pre>\n<p>  \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f polls \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0444\u0430\u0439\u043b\u0435 users\/urls.py \u2014 \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e <a href=\"https:\/\/github.com\/natkaida\/blogit\/blob\/main\/polls\/urls.py\">\u0441\u0441\u044b\u043b\u043a\u0435<\/a>.<\/p>\n<p>  \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 polls \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Chart.j: \u043b\u043e\u0433\u0438\u043a\u0430 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c \u043e\u043f\u0438\u0441\u0430\u043d\u0430 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>results<\/code>. <\/p>\n<pre><code class=\"plaintext\">def results(request, question_id):     profile = request.user.profile     question = get_object_or_404(Question, pk=question_id)     labels = []     data = []     votes = question.choice_set.select_related('question').all()       for item in votes:         labels.append(item.name)         data.append(item.votes)      context = {'question': question,      'profile': profile,      'labels': labels,      'data': data}         return render(request, 'polls\/results.html', context)<\/code><\/pre>\n<p>  <i>\u041f\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0432\u044b\u043d\u043e\u0441\u0438\u0442\u0435 \u043b\u043e\u0433\u0438\u043a\u0443 \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440\u043e\u0432 \u0438\u0437 views \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u0438.<\/i><\/p>\n<p>  \u0412\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 <a href=\"https:\/\/github.com\/natkaida\/blogit\/tree\/main\/polls\/templates\/polls\">polls\/emplates\/polls<\/a>:  <\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/natkaida\/blogit\/blob\/main\/polls\/templates\/polls\/question.html\">question.html<\/a> \u2014 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u0441 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430\u043c\u0438 \u043e\u0442\u0432\u0435\u0442\u0430,<\/li>\n<li><a href=\"https:\/\/github.com\/natkaida\/blogit\/blob\/main\/polls\/templates\/polls\/questions.html\">questions.html<\/a> \u2014 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 \u0432\u0441\u0435\u0445 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u043f\u0440\u043e\u0441\u043e\u0432,<\/li>\n<li><a href=\"https:\/\/github.com\/natkaida\/blogit\/blob\/main\/polls\/templates\/polls\/results.html\">results.html<\/a> \u2014 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u044f.<\/li>\n<\/ul>\n<p>  \u041c\u0435\u0442\u043e\u0434 user_voted <a href=\"https:\/\/github.com\/natkaida\/blogit\/blob\/main\/polls\/models.py\">\u043a\u043b\u0430\u0441\u0441\u0430 Question<\/a> \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u043b \u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0443\u0447\u0430\u0441\u0442\u0438\u0435 \u0432 \u043e\u043f\u0440\u043e\u0441\u0435 (\u043f\u0440\u043e\u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437). \u041b\u043e\u0433\u0438\u043a\u0430 \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043e\u043f\u0440\u043e\u0441\u0430 \u043e\u043f\u0438\u0441\u0430\u043d\u0430 \u0432 <a href=\"https:\/\/github.com\/natkaida\/blogit\/blob\/main\/polls\/views.py\">polls\/views.py<\/a>. \u0424\u0443\u043d\u043a\u0446\u0438\u044f vote \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442 \u0441\u043b\u0443\u0447\u0430\u0438, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u0432\u044b\u0431\u0440\u0430\u043b \u043d\u0438 \u043e\u0434\u0438\u043d \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043e\u0442\u0432\u0435\u0442\u0430, \u0438 \u043a\u043e\u0433\u0434\u0430 \u043e\u043d \u0443\u0436\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u043b \u0443\u0447\u0430\u0441\u0442\u0438\u0435 \u0432 \u043e\u043f\u0440\u043e\u0441\u0435. <\/p>\n<p>  <font color=\"#EB4247\"><\/p>\n<h2>\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 quizzes<\/h2>\n<p><\/font>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/-h\/1j\/gs\/-h1jgsbhjvjiojepejs4q7ax7fa.png\"><\/div>\n<p>  \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 <a href=\"https:\/\/github.com\/natkaida\/blogit\/tree\/main\/quizzes\">quizzes <\/a>\u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0434\u0432\u0443\u0445 \u0442\u0438\u043f\u043e\u0432 \u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u2014 \u0441 \u043e\u0434\u043d\u0438\u043c \u0438 \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c\u0438 \u043e\u0442\u0432\u0435\u0442\u0430\u043c\u0438. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0435\u0433\u043e, \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u0432 settings.py \u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0432 urls.py \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438. \u041c\u0430\u0440\u0448\u0440\u0443\u0442\u044b \u0441\u0430\u043c\u043e\u0433\u043e \u0431\u043b\u043e\u0433\u0430 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 <a href=\"https:\/\/github.com\/natkaida\/blogit\/blob\/main\/quizzes\/urls.py\">quizzes\/urls.py<\/a>, \u0430 \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u2014 \u0432<a href=\"https:\/\/github.com\/natkaida\/blogit\/tree\/main\/quizzes\/templates\/quizzes\"> quizzes\/templates\/quizzes<\/a>.<\/p>\n<p>  \u041c\u043e\u0434\u0443\u043b\u044c \u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0447\u0435\u0442\u044b\u0440\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u0430:  <\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/natkaida\/blogit\/blob\/main\/quizzes\/templates\/quizzes\/display.html\">display.html<\/a> \u2014 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u043e\u0442\u0432\u0435\u0442\u0430,<\/li>\n<li><a href=\"https:\/\/github.com\/natkaida\/blogit\/blob\/main\/quizzes\/templates\/quizzes\/quizzes.html\">quizzes.html<\/a> \u2014 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043f\u043e\u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0435\u0441\u0442\u043e\u0432,<\/li>\n<li><a href=\"https:\/\/github.com\/natkaida\/blogit\/blob\/main\/quizzes\/templates\/quizzes\/results.html\">results.html<\/a> \u2014 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u0440\u043e\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0442\u0435\u0441\u0442\u0430.<\/li>\n<li><a href=\"https:\/\/github.com\/natkaida\/blogit\/blob\/main\/quizzes\/templates\/quizzes\/partial.html\">partial.html<\/a> \u2014 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u2014 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0441 JS-\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u043c \u0432 \u0444\u0430\u0439\u043b\u0435 display.html \u2014 \u0432\u044b\u0432\u043e\u0434 \u0444\u0438\u0434\u0431\u0435\u043a\u0430 \u0431\u0435\u0437 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b,<\/li>\n<\/ul>\n<p>  \u041a\u043b\u0430\u0441\u0441 Question \u0432 <a href=\"https:\/\/github.com\/natkaida\/blogit\/blob\/main\/quizzes\/models.py\">quizzes\/models.py<\/a> \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0434\u0432\u0430 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u0430:  <\/p>\n<ul>\n<li><code>get_answers<\/code> \u2014 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u043e\u0442\u0432\u0435\u0442\u044b, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0438\u043f\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u0430,<\/li>\n<li><code>user_can_answer<\/code> \u2014 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u043e\u0442\u0432\u0435\u0447\u0430\u043b \u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u0440\u0430\u043d\u0435\u0435.<\/li>\n<\/ul>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432 <a href=\"https:\/\/github.com\/natkaida\/blogit\/blob\/main\/quizzes\/views.py\">quizzes\/views.py<\/a> \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0442 \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0442\u0435\u0441\u0442\u0430 \u0438 \u043e\u0446\u0435\u043d\u043a\u0443 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u043f\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c \u0438 \u043d\u0435\u0432\u0435\u0440\u043d\u044b\u043c \u043e\u0442\u0432\u0435\u0442\u0430\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043b\u0430\u0441\u0441\u0430 <code>Result<\/code>. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 <code>F<\/code>.<\/p>\n<pre><code class=\"plaintext\">result, created = Result.objects.get_or_create(user=request.user,      quiz=quiz) if is_correct is True:     result.correct = F('correct') + 1 else:     result.wrong = F('wrong') + 1<\/code><\/pre>\n<p>  \u0413\u043e\u0442\u043e\u0432\u043e \u2014 \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0431\u043b\u043e\u0433 \u0432 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d!<\/p>\n<h3>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u043e\u0432 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435<\/h3>\n<p>  \u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u0443\u0436\u0435 \u0430\u0440\u0435\u043d\u0434\u043e\u0432\u0430\u043b\u0438 <a href=\"https:\/\/selectel.ru\/services\/cloud\/sharedline\/?utm_source=habr.com&amp;utm_medium=referral&amp;utm_campaign=cloud_article_gjango_310523_content\">\u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440<\/a> \u0441 \u0433\u0438\u0431\u043a\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u044f\u0434\u0440\u0430 \u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043b\u0438 \u043a\u043e\u0434 \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u0435\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u2014 \u0437\u0430\u0434\u0435\u043f\u043b\u043e\u0438\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f polls \u0438 quizzes. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0448\u0438\u0442\u044c \u0438\u0445 \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u043d\u0430 GitHub, \u0430 \u043f\u043e\u0441\u043b\u0435 \u2014 \u0441\u0434\u0435\u043b\u0430\u0442\u044c <code>git pull<\/code> \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430.<\/p>\n<p>  <a href=\"https:\/\/selectel.ru\/services\/cloud\/sharedline\/?utm_source=habr.com&amp;utm_medium=referral&amp;utm_campaign=cloud_article_gjango_310523_banner\"><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/k5\/h7\/xu\/k5h7xuqzyygjvfyumceelhmk65q.png\"><\/div>\n<p><\/a><\/p>\n<p>  <font color=\"#EB4247\"><\/p>\n<h2>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 Nginx \u0438 Gunicorn<\/h2>\n<p><\/font><br \/>  \u041f\u0440\u0438 \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u043d\u0438\u0438 Django-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f Nginx \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u043a\u0441\u0438-\u0441\u0435\u0440\u0432\u0435\u0440\u0430: \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0430 80 \u043f\u043e\u0440\u0442 \u0438 \u043f\u0435\u0440\u0435\u0430\u0434\u0440\u0435\u0441\u0430\u0446\u0438\u044e \u0438\u0445 \u0432 Gunicorn. <\/p>\n<p>  Gunicorn \u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0440\u043e\u043b\u044c \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439: \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0437\u0430\u043f\u0443\u0441\u043a Django, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e \u043e\u0442\u0432\u0435\u0442\u043e\u0432. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e \u0442\u0430\u043a\u043e\u0439 \u0441\u0445\u0435\u043c\u0435:   <\/p>\n<ol>\n<li>\u041a\u043b\u0438\u0435\u043d\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 Nginx,<\/li>\n<li>Nginx \u043f\u0435\u0440\u0435\u0441\u044b\u043b\u0430\u0435\u0442 (\u043f\u0440\u043e\u043a\u0441\u0438\u0440\u0443\u0435\u0442) \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 Gunicorn \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b proxy pass?<\/li>\n<li>Gunicorn \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 Django,<\/li>\n<li>Django \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043e\u0442\u0432\u0435\u0442 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0432 Gunicorn,<\/li>\n<li>Gunicorn \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 Nginx, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0435\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0443.<\/li>\n<\/ol>\n<p>  \u041f\u0440\u0438 \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 Nginx \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u0443\u044e \u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0430 Gunicorn \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u0434\u043b\u044f \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a \u0438 \u043f\u043b\u0430\u0432\u043d\u043e\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0447\u0438\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432. <\/p>\n<h3>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 Gunicorn<\/h3>\n<p>  \u0412 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 \u043d\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e: \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<pre><code class=\"plaintext\">source blogitenv\/bin\/activate pip install gunicorn<\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435 \u0438 \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 <a href=\"https:\/\/github.com\/natkaida\/blogit\/blob\/main\/config\/settings.py\">config\/settings.py<\/a>, \u043a\u0430\u043a \u0431\u044b\u043b\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438. \u0410 \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0441\u0443\u043f\u0435\u0440\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0441\u043e\u0431\u0435\u0440\u0438\u0442\u0435 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0444\u0430\u0439\u043b\u044b. <\/p>\n<pre><code class=\"plaintext\">python3 manage.py migrate python3 manage.py createsuperuser python3 manage.py collectstatic<\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 Gunicorn, \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0432 \u0435\u0433\u043e \u0432 \u0441\u0432\u044f\u0437\u043a\u0435 \u0441 Django-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c.<\/p>\n<pre><code class=\"plaintext\">gunicorn --bind 0.0.0.0:8000 config.wsgi<\/code><\/pre>\n<p>  \u0412\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442: \u043a \u0431\u043b\u043e\u0433\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043f\u043e IP-\u0430\u0434\u0440\u0435\u0441\u0443 \u0447\u0435\u0440\u0435\u0437 8000-\u043f\u043e\u0440\u0442. \u041d\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0435\u0440 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0432\u0440\u0443\u0447\u043d\u0443\u044e. \u0412 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0435 \u044d\u0442\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u2014 \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c Gunicorn \u0438 Nginx \u0434\u043b\u044f \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e\u0433\u043e \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u043d\u0438\u044f Django-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. <\/p>\n<blockquote><p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u044d\u0442\u0438 \u0442\u0435\u043a\u0441\u0442\u044b \u0442\u043e\u0436\u0435 \u0432\u0430\u0441 \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0442:<\/p>\n<p>  \u2192 <a href=\"https:\/\/habr.com\/ru\/companies\/selectel\/articles\/731506\/\">\u041f\u0440\u043e\u0441\u0442\u0430\u044f \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u043d\u0430\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043c\u0438\u0440\u0430, \u0438\u043b\u0438 \u0428\u0443\u043c\u044b \u041f\u0435\u0440\u043b\u0438\u043d\u0430 \u043d\u0430 Python<\/a><br \/>  \u2192 <a href=\"https:\/\/habr.com\/ru\/companies\/selectel\/articles\/734194\/\">\u00ab\u041a\u0430\u0440\u043c\u0430\u043d\u043d\u044b\u0439 \u0441\u0438\u043d\u043e\u043f\u0442\u0438\u043a \u0437\u0430 \u0447\u0430\u0441\u00bb. \u041f\u0438\u0448\u0435\u043c Telegram-\u0431\u043e\u0442\u0430 \u0434\u043b\u044f \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u043f\u043e\u0433\u043e\u0434\u044b \u043d\u0430 Python<\/a><br \/>  \u2192 <a href=\"https:\/\/habr.com\/ru\/companies\/selectel\/articles\/729828\/\">\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0432\u0435\u0442\u0445\u043e\u0437\u0430\u0432\u0435\u0442\u043d\u0443\u044e \u0438\u0441\u0442\u043e\u0440\u0438\u044e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0447\u0435\u043b\u043e\u0432\u0435\u0447\u0435\u0441\u0442\u0432\u0430 \u043e\u0442 \u0410\u0434\u0430\u043c\u0430 \u0438 \u0415\u0432\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u043e\u043f\u0443\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438<\/a><\/p><\/blockquote>\n<p>  <\/p>\n<h3>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 Gunicorn<\/h3>\n<p>  \u0414\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 Django-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b gunicorn.socket \u0438 gunicorn.service. \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043f\u0435\u0440\u0432\u043e\u0433\u043e: <\/p>\n<pre><code class=\"plaintext\">sudo nano \/etc\/systemd\/system\/gunicorn.socket<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">[Unit] Description=Gunicorn socket   [Socket] ListenStream=\/run\/gunicorn.sock   [Install] WantedBy=sockets.target<\/code><\/pre>\n<p>  <i>\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0444\u0430\u0439\u043b\u0430 gunicorn.socket<\/i><\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c gunicorn.service \u0438 \u0443\u043a\u0430\u0436\u0435\u043c \u043d\u0430 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0435\u0440.<\/p>\n<pre><code class=\"plaintext\">sudo nano \/etc\/systemd\/system\/gunicorn.service<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">[Unit] Description=Gunicorn daemon Requires=gunicorn.socket After=network.target   [Service] User=root Group=www-data WorkingDirectory=\/root\/blogit ExecStart=\/root\/blogitenv\/bin\/gunicorn \\       --access-log file - \\       --workers 5 \\       --bind unix:\/run\/gunicorn.sock \\       config.wsgi:application   [Install] WantedBy=multi-user.target<\/code><\/pre>\n<p>  <i>\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0444\u0430\u0439\u043b\u0430 gunicorn.service<\/i><\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c Gunicorn \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0435\u0433\u043e \u0441\u0442\u0430\u0442\u0443\u0441. <\/p>\n<pre><code class=\"plaintext\">sudo systemctl start gunicorn.socket sudo systemctl enable gunicorn.socket sudo systemctl start gunicorn.service sudo systemctl enable gunicorn.service  sudo systemctl status gunicorn<\/code><\/pre>\n<p>  \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0432\u0435\u0440\u043d\u0435\u0442 \u0441\u0442\u0430\u0442\u0443\u0441 running \u0438 \u0432\u044b\u0432\u0435\u0434\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e workers \u2014 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0445 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0430\u0445 Django-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0412 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435 gunicorn.service \u043c\u044b \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u043f\u044f\u0442\u044c \u00ab\u0432\u043e\u0440\u043a\u0435\u0440\u043e\u0432\u00bb \u2014 Gunicorn \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u0445 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c. <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ga\/_8\/xi\/ga_8xi2r6drwputn-drf_hmwnsc.png\"><\/div>\n<p>  <\/p>\n<h3>\u041f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 <\/h3>\n<p>  \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u044d\u0442\u0430\u043f\u043e\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 Nginx \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441 80 \u043f\u043e\u0440\u0442\u0430 \u043d\u0430 Gunicorn. <\/p>\n<pre><code class=\"plaintext\">sudo nano \/etc\/nginx\/sites-available\/blogit<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">server { listen 80; server_name 94.26.224.162; access_log \/var\/log\/nginx\/access.log; error_log \/var\/log\/nginx\/error.log;   location = \/favicon.ico {     alias \/root\/blogit\/static\/favicon.ico; }    location \/static\/ {     alias \/root\/blogit\/static\/; }   location \/media\/ {     alias \/root\/blogit\/media\/; }   location \/ {     include proxy_params;     proxy_pass http:\/\/unix:\/run\/gunicorn.sock; } }<\/code><\/pre>\n<p>  <i>\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0444\u0430\u0439\u043b\u0430 \/etc\/nginx\/sites-available\/blogit. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 server_name \u0443\u043a\u0430\u0436\u0438\u0442\u0435 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 IP-\u0430\u0434\u0440\u0435\u0441 \u0441\u0432\u043e\u0435\u0439 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u044b.<\/i><\/p>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438, \u0441\u0432\u044f\u0436\u0438\u0442\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b Nginx \u2014 sites-available \u0438 sites-enabled \u2014 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0438\u043c\u0432\u043e\u043b\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0438:<\/p>\n<pre><code class=\"plaintext\">sudo ln -s \/etc\/nginx\/sites-available\/blogit \/etc\/nginx\/sites-enabled\/<\/code><\/pre>\n<p>  <b>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435:<\/b> \u0435\u0441\u043b\u0438 \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u0430\u0445 \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0430, \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0437\u0430\u043d\u043e\u0432\u043e, \u043d\u043e \u0443\u0436\u0435 \u0441 \u0444\u043b\u0430\u0433\u043e\u043c -sf.<\/p>\n<pre><code class=\"plaintext\">sudo ln -sf \/etc\/nginx\/sites-available\/blogit \/etc\/nginx\/sites-enabled\/ sudo systemctl reload nginx<\/code><\/pre>\n<p>  \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0435\u0441\u043b\u0438 \u0432\u044b \u0440\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442\u0435 \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0435 \u043f\u043e\u0434 root, \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0438\u0442\u044c \u043f\u0440\u0430\u0432\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0434\u043b\u044f \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0439 static \u0438 media.<\/p>\n<pre><code class=\"plaintext\">chown -R django_user:www-data \/var\/www\/blogit\/static\/ chown -R django_user:www-data \/var\/www\/blogit\/media<\/code><\/pre>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 Nginx \u0438 Gunicorn \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0441\u0430\u0439\u0442 \u0447\u0435\u0440\u0435\u0437 \u0431\u0440\u0430\u0443\u0437\u0435\u0440. \u041f\u0440\u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0438 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0430\u0440\u0435\u043d\u0434\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u043c\u0435\u043d\u043d\u043e\u0435 \u0438\u043c\u044f \u0438 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c SSL-\u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/mq\/9v\/k6\/mq9vk62qqoymqynbnpenej3fnfw.png\"><\/div>\n<p>  <\/p>\n<blockquote><p>\u041c\u044b \u0432\u0441\u0435 \u0435\u0449\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u043b\u0438\u0448\u044c \u043c\u0430\u043b\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0431\u043b\u043e\u0433\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u0440\u043e\u043b\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e email-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/selectel.ru\/services\/additional\/smtp\/?utm_source=habr.com&amp;utm_medium=referral&amp;utm_campaign=cloud_article_gjango_310523_content\">\u043f\u043e\u0447\u0442\u043e\u0432\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 Selectel<\/a> (\u043d\u0430 \u0432\u0440\u0435\u043c\u044f \u0431\u0435\u0442\u044b \u2014 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u043e). <\/p>\n<p>  \u0410 \u043a\u0430\u043a\u0438\u0435 \u0431\u044b \u0444\u0438\u0447\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0432\u044b? \u041f\u043e\u0434\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u0441\u0432\u043e\u0438\u043c\u0438 \u0438\u0434\u0435\u044f\u043c\u0438 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445!<\/p><\/blockquote>\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\/companies\/selectel\/articles\/738942\/\"> https:\/\/habr.com\/ru\/companies\/selectel\/articles\/738942\/<\/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-1\">\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/a1\/k3\/fy\/a1k3fytzay17q3bya7b5dcaal80.png\"><\/div>\n<p>  \u0412 <a href=\"https:\/\/habr.com\/ru\/companies\/selectel\/articles\/735556\/\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438<\/a> \u043c\u044b \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438 \u0448\u0430\u0431\u043b\u043e\u043d \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0431\u043b\u043e\u0433\u0430, \u0432\u044b\u0431\u0440\u0430\u043b\u0438 <a href=\"https:\/\/selectel.ru\/services\/cloud\/servers\/?utm_source=habr.com&amp;utm_medium=referral&amp;utm_campaign=cloud_article_gjango_310523_content\">\u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u0443\u044e \u043c\u0430\u0448\u0438\u043d\u0443<\/a> \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u043d\u0430 \u043d\u0435\u0439 \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0435\u0440 Django. \u041e\u0434\u043d\u0430\u043a\u043e \u043e\u043d \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u0414\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c Nginx \u0438 WSGI Gunicorn. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c.   <\/p>\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-348166","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/348166","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=348166"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/348166\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=348166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=348166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=348166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}