{"id":301735,"date":"2020-04-13T03:00:13","date_gmt":"2020-04-13T03:00:13","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=301735"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2020-04-13T03:00:13","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=301735","title":{"rendered":"\u0412\u0435\u0441\u044c \u0425\u0430\u0431\u0440 \u0432 \u043e\u0434\u043d\u043e\u0439 \u0431\u0430\u0437\u0435. \u041a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0438 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/496892\/\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/so\/j_\/57\/soj_579dmp8ray0fn7srtcpgmyu.png\" alt=\"\u041a\u0414\u041f\u0412\"> <\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/habr.com\/post\/490820\/\">\u0427\u0430\u0441\u0442\u044c 1<\/a> | <a href=\"https:\/\/mega.nz\/#F!2ToAVa7Y!ZxnFgMjMVMyo07LC1W0IaQ\" rel=\"nofollow\">mega.nz<\/a> | <a href=\"http:\/\/vitka-k.ru:3031\/\" rel=\"nofollow\">\u041e\u043d\u043b\u0430\u0439\u043d \u0434\u0435\u043c\u043e<\/a><\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u044d\u0442\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044f \u043f\u0430\u0440\u0441\u0438\u043b \u0425\u0430\u0431\u0440 \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445. \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0441\u0442\u0430\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0435\u0451 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h2 id=\"malenkie-pravki-uproschayuschie-zhizn\">\u041c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0435 \u043f\u0440\u0430\u0432\u043a\u0438, \u0443\u043f\u0440\u043e\u0449\u0430\u044e\u0449\u0438\u0435 \u0436\u0438\u0437\u043d\u044c<\/h2>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445<\/b><\/p>\n<div class=\"spoiler_text\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/dc\/zy\/9r\/dczy9rs2n_k2pwjs9jyct_1mahq.png\"><\/p>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p>\u0423\u0441\u043a\u043e\u0440\u044f\u0435\u043c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u0430.<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">CREATE INDEX article_indx ON articles(id); CREATE INDEX comments_indx ON comments(article);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0440\u0435\u043c\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u2014 1 \u0441.<\/p>\n<p>  <\/p>\n<p>\u0412\u0440\u0435\u043c\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u2014 5 \u043c\u0441.<\/p>\n<p>  <\/p>\n<p>\u0412\u0440\u0435\u043c\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u2014 10 \u043c\u0441.<\/p>\n<p>  <\/p>\n<h2 id=\"parsim-kommentarii\">\u041f\u0430\u0440\u0441\u0438\u043c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438<\/h2>\n<p>  <\/p>\n<p>\u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u043d\u0435 \u043f\u043e\u0441\u043e\u0432\u0435\u0442\u043e\u0432\u0430\u043b\u0438 \u0440\u0430\u0437\u0432\u0438\u0442\u044c \u0438\u0434\u0435\u044e \u0432\u0441\u0442\u0430\u0432\u043a\u0438 \u0432 \u0431\u0430\u0437\u0443 \u0441\u0440\u0430\u0437\u0443, \u0431\u0435\u0437 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u043e\u0433\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043d\u0430 \u0434\u0438\u0441\u043a\u0435 (SSD \u0441\u043a\u0430\u0437\u0430\u043b \u043c\u043d\u0435 \u0441\u043f\u0430\u0441\u0438\u0431\u043e).<\/p>\n<p>  <\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0438\u0437-\u0437\u0430 \u043c\u043e\u0435\u0439 \u043a\u0440\u0438\u0432\u043e\u0441\u0442\u0438 \u0440\u0443\u043a \u043c\u043d\u0435 \u043d\u0435 \u0445\u0432\u0430\u0442\u0438\u043b\u043e \u0442\u0435\u0440\u043f\u0435\u043d\u0438\u044f \u0440\u0435\u0448\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0435\u0449\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u044f \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438(\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0436\u0435 \u0431\u043e\u043b\u0438 \u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0437\u0430 \u044d\u0442\u0438\u043c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c). \u0414\u0430 \u0437\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0435\u0442 sqlite3worker \u0438 \u0435\u0433\u043e \u0430\u0432\u0442\u043e\u0440. \u0415\u0433\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0435 \u0437\u0430\u0434\u0443\u043c\u044b\u0432\u0430\u044f\u0441\u044c \u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0435, \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0431\u0430\u0437\u044b \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0432\u0430\u0436\u043d\u044b\u0445 \u0432\u0435\u0449\u0430\u0445.<\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">from sqlite3worker import Sqlite3Worker from multiprocessing.dummy import Pool as ThreadPool from datetime import datetime import json import requests import logging  sql_worker = Sqlite3Worker(&quot;habr.db&quot;) sql_worker.execute(&quot;CREATE TABLE IF NOT EXISTS comments(id INTEGER,&quot;                    &quot;parent_id INTEGER,&quot;                    &quot;article INTEGER,&quot;                    &quot;level INTEGER,&quot;                    &quot;timePublished TEXT,&quot;                    &quot;score INTEGER,&quot;                    &quot;message TEXT,&quot;                    &quot;children TEXT,&quot;                    &quot;author TEXT)&quot;)  def worker(i):     url = &quot;https:\/\/m.habr.com\/kek\/v2\/articles\/{}\/comments\/?fl=ru%2Cen&amp;hl=ru&quot;.format(i)      try:         r = requests.get(url)         if r.status_code == 503:             logging.critical(&quot;503 Error&quot;)             raise SystemExit     except:         with open(&quot;req_errors.txt&quot;, &quot;a&quot;) as file:             logging.critical(&quot;requests error&quot;)             file.write(str(i))         return 2      try: data = json.loads(r.text)     except: logging.warning(&quot;[{}] Json loads failed&quot;.format(i))      if data['success']:         comments = data['data']['comments']          for comment in comments:             current = comments[comment]              id = current['id']             parent_id = current['parentId']             article = i             level = current['level']             time_published = current['timePublished']             score = current['score']             message = current['message']             children = [children for children in current['children']]             author = current['author']              try: data = (id,                     parent_id,                     article,                     level,                     time_published,                     score,                     message,                     str(children),                     str(author['login']))             except:                 data = (None, None, None, None, None, None, None, None, None)              sql_worker.execute(&quot;INSERT INTO comments VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)&quot;, data)          logging.info(&quot;Comments on article {} were parsed&quot;.format(i))  min = 490000 max = 495000 pool = ThreadPool(3)  start_time = datetime.now() results = pool.map(worker, range(min, max))  pool.close() pool.join() sql_worker.close() print(datetime.now() - start_time)<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0433\u0440\u0430\u043c\u043e\u0442\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0432 \u0431\u0430\u0437\u0435 \u0434\u043e \u043c\u0435\u043d\u044f \u0443\u0436\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043b <a href=\"https:\/\/habr.com\/ru\/users\/dug\/\" class=\"user_link\">dug<\/a> \u0432 \u0441\u0432\u043e\u0435\u0439 <a href=\"https:\/\/habr.com\/ru\/post\/125729\/\">\u0441\u0442\u0430\u0442\u044c\u0435<\/a>.<br \/>  \u0417\u0430 \u043c\u0435\u043d\u044f \u0432\u0441\u0435 \u0443\u0436\u0435 \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0430\u0432\u0442\u043e\u0440\u044b \u0425\u0430\u0431\u0440\u0430 \u0438 \u043c\u043d\u0435 \u043e\u0441\u0442\u0430\u0432\u0430\u043b\u043e\u0441\u044c \u043b\u0438\u0448\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043f\u043e\u043b\u044f \u0432 \u0431\u0430\u0437\u0435. <\/p>\n<p>  <\/p>\n<h2 id=\"veb-prilozhenie\">\u0412\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>\u0421\u0430\u043c\u0430\u044f, \u043a\u0430\u043a \u043c\u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u0438 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<br \/>  \u0414\u043b\u044f \u0435\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0432\u044b\u0431\u0440\u0430\u043b Flask, \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0440\u0430\u043d\u044c\u0448\u0435 \u0438\u043c\u0435\u043b \u0441 \u043d\u0438\u043c \u0434\u0435\u043b\u043e \u0438 \u043e\u043d \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442 \u0434\u043b\u044f \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u0441\u0442\u0430\u0440\u0442\u0430. <\/p>\n<p>  <\/p>\n<h4 id=\"sozdaem-prilozhenie\">\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435<\/h4>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043e\u0431\u044b\u0447\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 Flask, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435.<br \/>  DEBUG \u2014 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430\u043c \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u2014 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u0438 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u0445 \u0432 \u043d\u0451\u043c. \u0422.\u0435. \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0432 \u0440\u0443\u0447\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0432\u043d\u0435\u0441\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u0434. <\/p>\n<p>  <\/p>\n<pre><code class=\"python\">from flask import Flask, g, render_template, request, redirect, url_for import sqlite3  app = Flask(__name__) app.config['DEBUG'] = True app.config['SECRET_KEY'] = 'supersecretkey'  DATABASE = &quot;.\/habr.db&quot;<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"funkciya-pomoschnik\">\u0424\u0443\u043d\u043a\u0446\u0438\u044f-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a<\/h4>\n<p>  <\/p>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0430\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445. <\/p>\n<p>  <\/p>\n<pre><code class=\"python\">def get_db():     db = getattr(g, '_database', None)     if db is None:         db = g._database = sqlite3.connect(DATABASE)     return db<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"glavnaya-stranica\">\u0413\u043b\u0430\u0432\u043d\u0430\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430<\/h4>\n<p>  <\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0433\u043b\u0430\u0432\u043d\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0448\u0430\u0431\u043b\u043e\u043d \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b. \u041f\u043e\u0437\u0436\u0435 \u043c\u044b \u0435\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043c, \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0447\u0443\u0442\u043e\u0447\u043a\u0443 \u043f\u043e\u043b\u0435\u0437\u043d\u0435\u0435.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">@app.route(&quot;\/&quot;) def index():     return render_template(&quot;index.html&quot;)<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"stranica-posta\">\u0421\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u043f\u043e\u0441\u0442\u0430<\/h4>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \/post\/<strong><em>id<\/em><\/strong>, \u0433\u0434\u0435 \u0434\u0435\u043b\u0430\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0431\u0430\u0437\u0435 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0448\u0430\u0431\u043b\u043e\u043d. <\/p>\n<p>  <\/p>\n<pre><code class=\"python\">@app.route('\/post\/&lt;int:post_id&gt;\/') def show_post(post_id):     cur = get_db().cursor()     res = cur.execute(&quot;SELECT * FROM articles WHERE id = :id&quot;, {&quot;id&quot;: post_id} )     article = res.fetchone()      return render_template(&quot;post.html&quot;, post=article)<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"shablony\">\u0428\u0430\u0431\u043b\u043e\u043d\u044b<\/h4>\n<p>  <\/p>\n<h5 id=\"postid-page\">\/post\/id page<\/h5>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u0445. \u0412\u043e Flask \u0434\u043b\u044f \u0440\u0435\u043d\u0434\u0435\u0440\u0430 html-\u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u044b.<br \/>  \u0414\u043b\u044f \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0430\u043f\u043a\u0443 templates \u0438 \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432 \u043d\u0435\u0451 html-\u0444\u0430\u0439\u043b\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u043c Jinja.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0442\u044c \u0432 \u0442\u0435\u0433 title \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043d\u0430\u0448\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u043d\u0430\u0448 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432 \u0434\u0432\u0435 \u0444\u0438\u0433\u0443\u0440\u043d\u044b\u0435 \u0441\u043a\u043e\u0431\u043a\u0438. <\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043b\u0443\u0447\u0448\u0435\u0433\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f, \u044d\u0442\u0443 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u0430\u043a <code>{{ var }} = print(var)<\/code> \u0432 Python.<\/p>\n<p>  <\/p>\n<pre><code class=\"html\">&lt;!doctype html&gt; &lt;html lang=&quot;en&quot;&gt; &lt;head&gt; &lt;meta charset=&quot;UTF-8&quot;&gt;              &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0&quot;&gt;                          &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;ie=edge&quot;&gt;              &lt;title&gt;{{ post[3] }}&lt;\/title&gt; &lt;\/head&gt; &lt;body&gt;  &lt;\/body&gt; &lt;\/html&gt;<\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445<\/b><\/p>\n<div class=\"spoiler_text\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/dc\/zy\/9r\/dczy9rs2n_k2pwjs9jyct_1mahq.png\"><\/p>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u043d\u0430\u043c \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432 \u043d\u0443\u0436\u043d\u044b\u0445 \u043c\u0435\u0441\u0442\u0430\u0445 \u043d\u0430\u0448\u0438 \u0434\u0430\u043d\u043d\u044b\u0435.<br \/>  \u0420\u0430\u0434\u0438 \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u0438 \u044f \u0441\u043e\u043a\u0440\u0430\u0449\u0443 \u043a\u043e\u0434 \u0434\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0433\u043e. \u0412\u0435\u0441\u044c \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 <a href=\"https:\/\/github.com\/viktor02\/habrmirror\/blob\/master\/templates\/post.html\" rel=\"nofollow\">\u0433\u0438\u0442\u0445\u0430\u0431\u0435<\/a><\/p>\n<p>  <\/p>\n<pre><code class=\"html\">&lt;div class=&quot;header&quot;&gt;     &lt;h1 class=&quot;display-4&quot;&gt;{{ post[3] }}&lt;\/h1&gt;     &lt;br&gt;     &lt;p class=&quot;&quot;&gt;         &lt;strong&gt;{{ date }}&lt;\/strong&gt; \u043e\u0442 &lt;strong&gt; {{ post[2] }}&lt;\/strong&gt;     &lt;\/p&gt;      &lt;!--  \u0415\u0441\u043b\u0438 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u0435\u0442\u043a\u0430 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u044d\u0442\u043e \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b  --&gt;     {% if post[9] == 1 %}         &lt;mark&gt;Tutorial&lt;\/mark&gt; &lt;br&gt;     {% endif %}      &lt;!--  6 - \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438, 8 - \u0440\u0435\u0439\u0442\u0438\u043d\u0433, 7 - \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043d\u043e \u0440\u0430\u0437  --&gt;     &lt;i class=&quot;fas fa-comments&quot;&gt;&lt;\/i&gt; {{ post[6] }} |     &lt;i class=&quot;fas fa-arrows-alt-v&quot;&gt;&lt;\/i&gt; {{ post[8] }} |     &lt;i class=&quot;fas fa-eye&quot;&gt;&lt;\/i&gt; {{ post[7] }} \u0440\u0430\u0437 &lt;\/div&gt;     &lt;div class=&quot;content&quot;&gt;         &lt;div&gt;             &lt;!-- safe - \u043f\u0435\u0447\u0430\u0442\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044f \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u043e\u0444\u043e\u0440\u043c\u043b\u0435\u043d\u0438\u0435, \u043d\u0435 \u043a\u043e\u0434\u0438\u0440\u0443\u044f \u0442\u0435\u0433\u0438 \u0432 \u0442\u0435\u043a\u0441\u0442     --&gt;             &lt;p&gt;{{ post[4]|safe }}&lt;\/p&gt;         &lt;\/div&gt;         &lt;br&gt;         &lt;strong&gt;&lt;i class=&quot;fas fa-tags&quot;&gt;&lt;\/i&gt; \u0422\u0435\u0433\u0438:&lt;\/strong&gt; {{ post[10] }}     &lt;\/div&gt; &lt;\/div&gt;<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"kommentarii\">\u041a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438<\/h4>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445. \u0412 \u0431\u0430\u0437\u0435 \u043e\u043d\u0438 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>comments<\/code>.<br \/>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043c \u0435\u0449\u0435 \u043e\u0434\u043d\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u043a \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c\u0443 \u0441\u043a\u0440\u0438\u043f\u0442\u0443<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">@app.route('\/post\/&lt;int:post_id&gt;\/') def show_post(post_id):     cur = get_db().cursor()      ...      res = cur.execute(&quot;SELECT * FROM comments WHERE article = :id&quot;, {&quot;id&quot;: post_id} )     comments = res.fetchall()      return render_template(&quot;post.html&quot;, post=article, comments=comments)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u0438\u0445 \u0432 \u043d\u0430\u0448\u0435\u043c \u0448\u0430\u0431\u043b\u043e\u043d\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"html\">&lt;div id=&quot;comments&quot;&gt;     &lt;h2&gt;\u041a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438&lt;\/h2&gt;     {% for comment in comments %}         &lt;div id=&quot;{{ comment[0] }}&quot; class=&quot;shadow-sm p-3 mb-5 bg-light rounded&quot;&gt;             &lt;div class=&quot;comment-header&quot;&gt;                 &lt;small&gt;#{{comment[0]}}&lt;\/small&gt;                 &lt;strong&gt;{{ comment[8] }}&lt;\/strong&gt;                 &lt;small&gt;{{comment[4]}} | &lt;i class=&quot;fas fa-arrows-alt-v&quot;&gt;&lt;\/i&gt; {{ comment[5] }}&lt;\/small&gt;             &lt;\/div&gt;             {% if comment[1] != 0 %}                 &lt;small&gt;&lt;a href=&quot;#{{comment[1]}}&quot;&gt;&lt;mark&gt;\u0412 \u043e\u0442\u0432\u0435\u0442 #{{ comment[1] }}&lt;\/mark&gt;&lt;\/a&gt;&lt;\/small&gt;                 {{comment[6]|safe}}             {% else %}                 {{comment[6]|safe}}             {% endif %}             &lt;br&gt;         &lt;\/div&gt;     {% endfor %} &lt;\/div&gt;<\/code><\/pre>\n<p>  <\/p>\n<p><em>\u0414\u043b\u044f \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 Jinja \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e {% %}<\/em><\/p>\n<p>  <\/p>\n<h5 id=\"index-page\">Index page<\/h5>\n<p>  <\/p>\n<p>\u041a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043e\u0441\u043e\u0431\u044b\u0445 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0435\u0439 \u043d\u0435\u0442 \u2014 \u043e\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u0440\u0438\u043b\u0438\u0447\u043d\u043e.<br \/>  \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043a \u0441\u0442\u0430\u0442\u044c\u044f\u043c, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u0444\u043e\u0440\u043c\u0443 \u0441 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u043c \u043f\u043e\u043b\u0435\u043c \u0438 \u043a\u043d\u043e\u043f\u043a\u043e\u0439.<br \/>  \u0421\u043a\u0440\u0438\u043f\u0442 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430 \u044d\u0442\u043e\u0439 \u0436\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c POST-\u0437\u0430\u043f\u0440\u043e\u0441 \u0438 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0430\u0441 \u043a \u0441\u0442\u0430\u0442\u044c\u0435:<br \/>  <em>main.py<\/em><\/p>\n<p>  <\/p>\n<pre><code class=\"python\">@app.route('\/', methods=['POST']) def index_post():     text = request.form['url']     id = ''.join(x for x in text if x.isdigit())     if id != '':         return redirect(url_for('show_post', post_id=id))     else: return &quot;\u041d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0439 \u0432\u0432\u043e\u0434&quot;<\/code><\/pre>\n<p>  <\/p>\n<p><em>index.html<\/em><\/p>\n<p>  <\/p>\n<pre><code class=\"html\">... &lt;form method=&quot;POST&quot;&gt;     &lt;input type=&quot;url&quot; name=&quot;url&quot;&gt;     &lt;div&gt;         &lt;button type=&quot;submit&quot; id=&quot;search&quot;&gt;\u041f\u0435\u0440\u0435\u0439\u0442\u0438&lt;\/button&gt;     &lt;\/div&gt; &lt;\/form&gt; ...<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u0442\u0430\u0442\u0435\u0439 \u0432 \u0431\u0430\u0437\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">@app.route(&quot;\/&quot;) def index():     cur = get_db().cursor()     res = cur.execute(&quot;SELECT min(id), max(id) FROM articles&quot;)     counter = res.fetchone()     return render_template(&quot;index.html&quot;, counter = counter)<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"html\">... &lt;div class=&quot;container&quot;&gt;         ...          &lt;p&gt;\u041f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u043a \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0441\u0442\u0430\u0442\u0435\u0439 = {{ counter[0] }}..{{ counter [1] }}&lt;\/p&gt;          ... &lt;\/div&gt; ...<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043a\u0430\u043a \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/hu\/oq\/dz\/huoqdzagizzjg65j206ujpura9e.png\"><\/p>\n<p>  <\/p>\n<h3 id=\"prochie-zhiznenno-neobhodimye-kostyli\">\u041f\u0440\u043e\u0447\u0438\u0435 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e-\u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043a\u043e\u0441\u0442\u044b\u043b\u0438<\/h3>\n<p>  <\/p>\n<ul>\n<li>\n<p>\u0418\u0442\u0430\u043a, \u043d\u0430\u0448\u0435 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0433\u043e\u0442\u043e\u0432\u043e. \u041e\u0434\u043d\u0430\u043a\u043e \u0435\u0441\u0442\u044c \u0448\u0435\u0440\u043e\u0445\u043e\u0432\u0430\u0442\u043e\u0441\u0442\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u0430\u0442\u0430 \u043f\u043e\u0441\u0442\u0430 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 ISO 8601, \u0447\u0442\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043d\u0435 \u0443\u0434\u043e\u0431\u043d\u043e \u0447\u0438\u0442\u0430\u0442\u044c.<br \/>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u043c \u044d\u0442\u043e: \u0431\u0443\u0434\u0435\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u0442\u0443 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0435\u0451 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0432 \u0448\u0430\u0431\u043b\u043e\u043d.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">import dateutil.parser from datetime import datetime ... @app.route('\/post\/&lt;int:post_id&gt;\/') def show_post(post_id): ... date = dateutil.parser.parse(article[1]) date = datetime.strftime(date, &quot;%d.%m.%Y %H:%M&quot;) ... return render_template(&quot;post.html&quot;, post=article, date=date, comments=comments)<\/code><\/pre>\n<p>  <\/li>\n<li>\n<p>\u0425\u0430\u0431\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 lazy load \u0434\u043b\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0438 \u0432 \u043d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">\/\/ \u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 (async () =&gt; { for (let node of document.getElementsByTagName('img')) {     await new Promise(res =&gt; {         if(node.dataset.src !== undefined){             node.src = node.dataset.src;             node.onload = () =&gt; res();         }     }) } })();<\/code><\/pre>\n<p>  <\/p>\n<p><em>\u041a\u0414\u041f\u0412, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0438 \u043e\u0442 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 data-src \u0442\u0435\u0433<\/em><\/p>\n<p>  <\/li>\n<li>\n<p>\u0412 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u043e\u0441\u0442\u0430\u0445 \u0435\u0441\u0442\u044c \u0441\u043f\u043e\u0439\u043b\u0435\u0440\u044b, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0436\u0435 &quot;\u043e\u0436\u0438\u0432\u0438\u043c&quot; \u0438\u0445:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$(document).on('click', '.spoiler_title', function (e) { e.preventDefault(); $(this).toggleClass('active'); $(this).parent().find('.spoiler_text').first().slideToggle(300); });<\/code><\/pre>\n<p>  <\/li>\n<li>\n<p>\u041d\u0443 \u0438 \u0432 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435. \u041c\u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043d\u0440\u0430\u0432\u0438\u043b\u0430\u0441\u044c \u0442\u0435\u043c\u043d\u0430\u044f \u0442\u0435\u043c\u0430, \u0431\u043b\u0430\u0433\u043e \u0435\u0451 \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u043c <a href=\"https:\/\/darkmodejs.learn.uno\/\" rel=\"nofollow\">Darkmode.js<\/a><\/p>\n<p>  <\/p>\n<pre><code class=\"html\">&lt;script src=&quot;https:\/\/cdn.jsdelivr.net\/npm\/darkmode-js@1.5.5\/lib\/darkmode-js.min.js&quot;&gt;&lt;\/script&gt; &lt;script&gt; new Darkmode().showWidget(); &lt;\/script&gt;<\/code><\/pre>\n<p>  <\/li>\n<\/ul>\n<p>  <\/p>\n<h2 id=\"razvorachivaem-na-boevom-servere\">\u0420\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u043d\u0430 \u0431\u043e\u0435\u0432\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435<\/h2>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043a\u043e\u043c\u0444\u043e\u0440\u0442\u043d\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0442\u043e\u0432\u0441\u044e\u0434\u0443, \u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0433\u0434\u0435-\u043d\u0438\u0431\u0443\u0434\u044c \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u0442\u044c(\u0412\u0430\u0448 \u043a\u044d\u043f).<\/p>\n<p>  <\/p>\n<h3 id=\"lokalno\">\u041b\u043e\u043a\u0430\u043b\u044c\u043d\u043e<\/h3>\n<p>  <\/p>\n<p>\u0412 \u0441\u0430\u043c\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u043c(\u043d\u043e \u043d\u0435 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u043c!) \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u043c \u0432\u043e flask \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c \u0441 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u043c \u0434\u0435\u0431\u0430\u0433\u0433\u0435\u0440\u043e\u043c. <\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">export FLASK_APP=main.py export FLASK_ENV=production flask run<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u043e, \u0445\u043e\u0442\u044c \u044f \u0438 \u043d\u0435 \u043d\u0430\u0448\u0435\u043b \u043f\u043e\u0447\u0435\u043c\u0443, \u043d\u0430\u0441 \u0432\u0435\u0437\u0434\u0435 \u0443\u0432\u0435\u0440\u044f\u044e\u0442, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0434\u043b\u044f \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0433\u043e \u0434\u0435\u043f\u043b\u043e\u044f \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e,<br \/>  \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0439 \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0435\u0440 uWSGI, \u043c\u043e\u0436\u043d\u043e \u0434\u0430\u0436\u0435 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 nginx. <\/p>\n<p>  <\/p>\n<h3 id=\"vsemu-miru\">\u0412\u0441\u0435\u043c\u0443 \u043c\u0438\u0440\u0443<\/h3>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0432\u0441\u0451 \u0433\u0440\u0430\u043c\u043e\u0442\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u2014 \u0443\u0436\u0435 \u0445\u043e\u0440\u043e\u0448\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u043b\u0438 \u0432 <a href=\"https:\/\/uwsgi-docs.readthedocs.io\/en\/latest\/WSGIquickstart.html\" rel=\"nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a> \u043a uWSGI, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c \u043d\u0435 \u0432\u0438\u0436\u0443 \u0441\u043c\u044b\u0441\u043b\u0430, \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u0430\u043c \u043b\u0438\u0441\u0442\u0438\u043d\u0433 \u043a\u043e\u043c\u0430\u043d\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u044f.<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">pip install uwsgi uwsgi --socket 0.0.0.0:3031 --protocol http --wsgi-file main.py --callable app<\/code><\/pre>\n<p>  <\/p>\n<p><em>\u041d\u0435 \u0443\u0432\u0435\u0440\u0435\u043d, \u0447\u0442\u043e \u044d\u0442\u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u2014 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u044f\u0442\u0430\u0442\u044c \u0437\u0430 nginx, \u043d\u043e \u044f \u0432 \u0435\u0433\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 \u043f\u0440\u043e\u0444\u0430\u043d<\/em><\/p>\n<p>  <\/p>\n<h2 id=\"konec\">\u041a\u043e\u043d\u0435\u0446<\/h2>\n<p>  <\/p>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u0435, \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0432\u0430\u043c \u0431\u044b\u043b\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e. \u0411\u0443\u0434\u0443 \u0440\u0430\u0434, \u0435\u0441\u043b\u0438 \u043a\u0442\u043e-\u0442\u043e \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u0441\u044f \u043a \u043f\u0440\u043e\u0435\u043a\u0442\u0443 \u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u0435\u0433\u043e \u043b\u0443\u0447\u0448\u0435. <\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442, \u043c\u043e\u0436\u043d\u043e <a href=\"http:\/\/vitka-k.ru:3031\" rel=\"nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>(\u0431\u0430\u0437\u0430 \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u044b\u0441\u044f\u0447 \u0441\u0442\u0430\u0442\u0435\u0439, \u0441\u0435\u0440\u0432\u0435\u0440 \u0432 \u0420\u043e\u0441\u0441\u0438\u0438).<br \/>  \u041d\u0443 \u0438 \u043a\u043e\u0434 \u043a\u0430\u043a \u0432\u0441\u0435\u0433\u0434\u0430 \u043d\u0430 <a href=\"https:\/\/github.com\/viktor02\/habrmirror\" rel=\"nofollow\">github<\/a><\/p>\n<p>  <\/p>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0438\u0437-\u0437\u0430 \u043c\u043e\u0435\u0433\u043e \u0441\u043b\u0430\u0431\u043e\u0433\u043e VPS \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0433\u043e \u0445\u0430\u0431\u0440\u0430\u044d\u0444\u0444\u0435\u043a\u0442\u0430 \u0441\u0430\u0439\u0442 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d. \u0411\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0435\u0441\u043b\u0438 \u043a\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u043e\u0434\u043d\u0438\u043c\u0435\u0442 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/496892\/\"> https:\/\/habr.com\/ru\/post\/496892\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/496892\/\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/so\/j_\/57\/soj_579dmp8ray0fn7srtcpgmyu.png\" alt=\"\u041a\u0414\u041f\u0412\"> <\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/habr.com\/post\/490820\/\">\u0427\u0430\u0441\u0442\u044c 1<\/a> | <a href=\"https:\/\/mega.nz\/#F!2ToAVa7Y!ZxnFgMjMVMyo07LC1W0IaQ\" rel=\"nofollow\">mega.nz<\/a> | <a href=\"http:\/\/vitka-k.ru:3031\/\" rel=\"nofollow\">\u041e\u043d\u043b\u0430\u0439\u043d \u0434\u0435\u043c\u043e<\/a><\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u044d\u0442\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044f \u043f\u0430\u0440\u0441\u0438\u043b \u0425\u0430\u0431\u0440 \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445. \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0441\u0442\u0430\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0435\u0451 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\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-301735","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/301735","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=301735"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/301735\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=301735"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=301735"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=301735"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}