{"id":416249,"date":"2024-06-30T00:50:49","date_gmt":"2024-06-30T00:50:49","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=416249"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=416249","title":{"rendered":"<span>\u041c\u043e\u0439 \u043f\u0443\u0442\u044c \u0432\u043e Flask. \u0427\u0430\u0441\u0442\u044c \u043f\u0435\u0440\u0432\u0430\u044f<\/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 \u0434\u043e\u0431\u0440\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0443\u0442\u043e\u043a. \u0412 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0434\u0432\u0430 \u0433\u043e\u0434\u0430 \u043d\u0430\u0437\u0430\u0434 \u044f \u0431\u044b\u043b \u043f\u0440\u043e\u0444\u0430\u043d, \u0438 \u043d\u0430\u0447\u0430\u043b \u0441 <em>Python<\/em>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0441 \u044d\u0442\u0438\u043c \u044f\u0437\u044b\u043a\u043e\u043c \u0431\u044b\u043b\u0430 \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u043c\u043e\u044f \u0434\u0438\u0441\u0441\u0435\u0440\u0442\u0430\u0446\u0438\u044f, \u043d\u043e \u043f\u043e\u043d\u044f\u043b, \u0447\u0442\u043e \u043d\u0435 \u0442\u044f\u043d\u0443 \u0432 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0438 \u0441\u0430\u043c \u0438 \u043f\u043e\u0448\u0435\u043b \u043d\u0430 \u043a\u0443\u0440\u0441\u044b, \u0433\u0434\u0435 \u043d\u0430\u0443\u0447\u0438\u043b\u0438 \u043e\u0441\u043d\u043e\u0432\u0430\u043c <em>Python<\/em>, \u043a\u0430\u043a \u0434\u0435\u043b\u0430\u0442\u044c \u0431\u043b\u043e\u0433-\u0441\u043e\u0446\u0441\u0435\u0442\u044c \u043d\u0430 <em>Django<\/em>, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 <em>API<\/em>, \u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e DevOps. \u041d\u043e \u043a\u0443\u0440\u0441\u044b \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438\u0441\u044c, \u0438 \u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441, \u00ab\u0447\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435?\u00bb. \u041f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u043c \u044f \u043d\u0435 \u043c\u043e\u0433\u0443 \u0441\u043c\u0435\u043d\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443, \u043d\u043e \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0445\u0432\u0430\u0442\u0430\u0435\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043b \u041b\u0443\u0442\u0446\u0430, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0434\u0442\u044f\u043d\u0443\u0442\u044c \u00ab\u043c\u0430\u0442\u0447\u0430\u0441\u0442\u044c\u00bb, \u0437\u0430\u0442\u0435\u043c \u00ab\u0427\u0438\u0441\u0442\u044b\u0439 \u043a\u043e\u0434\u00bb \u0420\u043e\u0431\u0435\u0440\u0442\u0430 \u041c\u0430\u0440\u0442\u0438\u043d\u0430. C\u0434\u0435\u043b\u0430\u043b \u043f\u0430\u0440\u043e\u0447\u043a\u0443 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u043d\u0430 <em>Django<\/em>, \u043e\u0434\u0438\u043d <em>API<\/em>, \u043f\u043e\u0443\u0447\u0438\u043b <em>JS<\/em>. \u0418 \u0441\u043d\u043e\u0432\u0430 \u0432\u043e\u0437\u043d\u0438\u043a \u0432\u043e\u043f\u0440\u043e\u0441, \u00ab\u0447\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435?\u00bb \u0411\u044b\u043b\u043e \u0434\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 <em>FastAPI<\/em> \u0438 <em>Flask<\/em>. \u0412\u044b\u0431\u043e\u0440 \u043f\u0430\u043b \u043d\u0430 <em>Flask<\/em>.<\/p>\n<p>\u0425\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043a\u0430\u043a \u0431\u044b \u0431\u043e\u0440\u0442\u043e\u0432\u043e\u0439 \u0436\u0443\u0440\u043d\u0430\u043b \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u0436\u0443\u043d\u043e\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e, \u0447\u0442\u043e \u043c\u0435\u0441\u0442\u0430\u043c\u0438 \u043c\u043e\u0433 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438. \u042f \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u0442\u043a\u0440\u044b\u0442 \u0434\u043b\u044f \u043a\u0440\u0438\u0442\u0438\u043a\u0438, \u043c\u043e\u044f \u0446\u0435\u043b\u044c \u2013 \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0438\u0441\u044c\u043c\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u0435\u0439, \u00a0\u0442\u0430\u043a \u043a\u0430\u043a \u0434\u0430\u043d\u043d\u0430\u044f (\u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442\u0441\u044f \ud83d\ude42 ) \u0431\u0443\u0434\u0435\u0442 \u0434\u0435\u0431\u044e\u0442\u043e\u043c.<\/p>\n<h3>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430<\/h3>\n<p>\u0421 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u043e\u0439 \u0432\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e. <\/p>\n<ol>\n<li>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0435 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 <code>venv<\/code><\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">py \u2013m venv venv # \u0438\u043b\u0438  python \u2013m venv venv # \u0438\u043b\u0438  python3 \u2013m venv venv<\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0435 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\"># Windows: source venv\/Scripts\/activate # \u0438\u043b\u0438 .\\venv\\Scripts\\activate # MacOS\/Ubuntu: source venv\/bin\/activate<\/code><\/pre>\n<ol start=\"3\">\n<li>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c <em>Flask<\/em> (\u0432\u0441\u0435 \u043d\u0443\u0436\u043d\u044b\u0435 \u043f\u0430\u043a\u0435\u0442\u044b <em>Flask<\/em> \u043f\u043e\u0434\u0442\u044f\u043d\u0435\u0442 \u0441\u0430\u043c):<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">pip install flask<\/code><\/pre>\n<p>\u0412\u0441\u0435 \u0433\u043e\u0442\u043e\u0432\u043e! \u0414\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u044d\u0442\u043e \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u043e \u0432 <a href=\"https:\/\/flask.palletsprojects.com\/en\/2.1.x\/installation\/\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a> .<\/p>\n<h3>Wake up, Neo\u2026<\/h3>\n<p>\u0414\u0435\u043b\u0430\u0435\u043c \u0441\u0430\u043c\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 \u0441\u0432\u0435\u0442\u0435.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b \u0432 \u0440\u0430\u0431\u043e\u0447\u0435\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0438 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u043a\u0430\u043a \u0443\u0433\u043e\u0434\u043d\u043e. \u041d\u0443\u0443\u0443, \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c, \u043a\u0430\u043a \u0443\u0433\u043e\u0434\u043d\u043e, \u0435\u0441\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0438\u043c\u0435\u043d\u0438 \u0444\u0430\u0439\u043b\u0430, \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0430\u044e\u0442, \u0447\u0442\u043e \u043d\u0435\u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0438\u043c\u044f \u0444\u0430\u0439\u043b\u0430 <code>flask.py<\/code>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442 \u0438\u043c\u0435\u043d \u0441 <em>Flask<\/em>.<\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043a\u043b\u0430\u0441\u0441 <code>Flask<\/code> \u0438\u0437 \u043c\u043e\u0434\u0443\u043b\u044f <code>flask<\/code><\/p>\n<pre><code class=\"python\">from flask import Flask<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u0421\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 (<code>app<\/code>) \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0448\u0438\u043c <abbr title=\"Web Server Gateway Interface\" type=\"abbr\">WSGI<\/abbr>-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c(\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0432 <a href=\"https:\/\/peps.python.org\/pep-3333\/\" rel=\"noopener noreferrer nofollow\">PEP 3333<\/a>).<\/p>\n<pre><code class=\"python\">app = Flask(__name__)<\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>__name__<\/code>, \u0432 \u043d\u0435\u0439 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0438\u043c\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043f\u043e\u0437\u0436\u0435, \u0430 \u043f\u043e\u043a\u0430 \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438: \u00ab<code>__name__<\/code> \u2014 \u044d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e\u0435 \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u0441\u043b\u0443\u0447\u0430\u0435\u0432. \u042d\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b <em>Flask<\/em> \u0437\u043d\u0430\u043b, \u0433\u0434\u0435 \u0438\u0441\u043a\u0430\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441\u044b, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u0448\u0430\u0431\u043b\u043e\u043d\u044b(<em>templates<\/em>) \u0438 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0444\u0430\u0439\u043b\u044b.\u00bb<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443:<\/p>\n<pre><code class=\"python\">def wake_up():     return 'Wake up, Neo...'<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0448\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u043e\u0431\u0449\u0438\u0442\u044c <em>Flask<\/em>, \u043f\u0440\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043a\u0430\u043a\u043e\u0433\u043e <em>URL<\/em>, \u0434\u043e\u043b\u0436\u043d\u0430 \u00ab\u0441\u0442\u0440\u0438\u0433\u0435\u0440\u0438\u0442\u044c\u0441\u044f\u00bb (\u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c\u0441\u044f) \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>wake_up<\/code>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0443 <em>Flask<\/em> \u0435\u0441\u0442\u044c \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 <code>route<\/code>:<\/p>\n<pre><code>@app.route('\/') def wake_up():     return 'Wake up, Neo...'<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u0432 \u043a\u043e\u0440\u0435\u043d\u044c \u0432\u044d\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u00ab<em>Wake up, Neo&#8230;<\/em>\u00bb.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435. \u0414\u043b\u044f \u0442\u0435\u0441\u0442\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440, \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c (\u0437\u0434\u0435\u0441\u044c \u0438 \u0434\u0430\u043b\u0435\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u0432\u0435\u0440\u0441\u0438\u0438 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f <em>Windows<\/em>).<\/p>\n<ol>\n<li>\n<p>\u0413\u043e\u0432\u043e\u0440\u0438\u043c \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0443, \u0441 \u043a\u0430\u043a\u0438\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c (\u0432 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0444\u0430\u0439\u043b \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>start.py<\/code>, \u043e\u0434\u043d\u0430\u043a\u043e \u0435\u0441\u043b\u0438 \u0444\u0430\u0439\u043b \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>app.py<\/code> \u0438\u043b\u0438 <code>wsgi.py<\/code>, \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u043d\u0435\u0442 \u043d\u0443\u0436\u0434\u044b \u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u0448\u0430\u0433, \u0442.\u043a. <em>Flask<\/em> \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u044d\u0442\u0438 \u0444\u0430\u0439\u043b\u044b \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c), \u043f\u0443\u0442\u0435\u043c \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f <code>FLASK_APP<\/code>:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">export FLASK_APP=start.py<\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p>\u0412\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0432\u0441\u0435 \u0444\u0438\u0447\u0438 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 (\u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0438 \u0434\u0435\u0431\u0430\u0433\u0435\u0440), \u043f\u0443\u0442\u0435\u043c \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f <code>FLASK_ENV<\/code>:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">export FLASK_ENV=development<\/code><\/pre>\n<ol start=\"3\">\n<li>\n<p>\u0418 \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u0435\u0440\u0432\u0435\u0440:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">flask run<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0432\u0432\u043e\u0434\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b <em>Flask<\/em> \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440, \u0430\u0434\u0440\u0435\u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043e\u0431\u044b\u0447\u043d\u043e <a href=\"http:\/\/127.0.0.1:5000\" rel=\"noopener noreferrer nofollow\">http:\/\/127.0.0.1:5000<\/a>. \u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u0430\u0434\u0440\u0435\u0441\u0443. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u0443\u0441\u0442\u0430\u044f \u0432\u044d\u0431-\u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043a\u0430 \u0441 \u043d\u0430\u0434\u043f\u0438\u0441\u044c\u044e <em>\u00abWake up, Neo\u2026\u00bb<\/em>.<\/p>\n<p>\u041d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435. \u041c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0447\u0435\u0440\u0435\u0437 \u0442\u043e\u0447\u043a\u0443 \u0432\u0445\u043e\u0434\u0430, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 \u043a\u043e\u043d\u0446\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"python\">if __name__ == \"__main__\":     app.run(debug=True)<\/code><\/pre>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0435\u0440\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u044d\u0442\u0438\u043c \u0437\u0430\u0442\u0440\u0443\u0434\u043d\u0435\u043d\u0438\u044f<\/h3>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0432\u043f\u043e\u043b\u043d\u0435 \u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u043c\u043e\u0434\u0435\u043b\u044f\u043c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 <em>Flask<\/em>, \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 <em>SQLAlchemy<\/em> (\u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u0430\u044f \u0441\u0432\u044f\u0437\u043a\u0430). \u0414\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435:<\/p>\n<pre><code class=\"bash\">pip install -U Flask-SQLAlchemy<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0432\u043e <em>Flask<\/em>, \u044f \u043e\u0431\u0440\u0430\u0442\u0438\u043b\u0441\u044f \u043a <a href=\"https:\/\/flask-sqlalchemy.palletsprojects.com\/en\/2.x\/\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Flask-SQLAlchemy<\/a>.<\/p>\n<p>\u0412 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 <a href=\"https:\/\/flask-sqlalchemy.palletsprojects.com\/en\/2.x\/quickstart\/\" rel=\"noopener noreferrer nofollow\">Quickstart <\/a>\u0435\u0441\u0442\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043b\u044f \u0440\u0430\u0437\u0431\u043e\u0440\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0435\u0433\u043e \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e, \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"python\">from flask import Flask from flask_sqlalchemy import SQLAlchemy  app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:\/\/\/\/database.db' db = SQLAlchemy(app)  class User(db.Model):     id = db.Column(db.Integer, primary_key=True)     username = db.Column(db.String(80), unique=True, nullable=False)     email = db.Column(db.String(120), unique=True, nullable=False)          def __repr__(self):         return '&lt;User %r>' % self.username<\/code><\/pre>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a <code>flask<\/code><em> <\/em>\u0438 <code>flask_sqlalchemy<\/code><em> <\/em>(\u043f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0435 \u0441\u0442\u0440\u043e\u0447\u043a\u0438), \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 (\u0441\u0442\u0440\u043e\u0447\u043a\u0430 4), \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0441 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0435\u0439 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 (\u0441\u0442\u0440\u043e\u0447\u043a\u0430 5), \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 <code>SQLAlchemy<\/code><em> (\u00ab<\/em>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0435\u0439 <em>SQLAlchemy<\/em> \u0432 \u043e\u0434\u043d\u043e \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 <em>Flask\u00bb)<\/em> \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0435\u043c\u0443 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f <code>Flask<\/code> (\u0441\u0442\u0440\u043e\u0447\u043a\u0430 6), \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441-\u043c\u043e\u0434\u0435\u043b\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (\u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c\u0441\u044f \u043e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 <code>SQLAlchemy<\/code>) (\u0441\u0442\u0440\u043e\u0447\u043a\u0430 8), \u0434\u0430\u043b\u0435\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u043e\u043b\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b (\u043c\u043e\u0434\u0435\u043b\u0438) c \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043b\u0430\u0441\u0441\u0430 <code>Column<\/code>, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441 \u0442\u0438\u043f\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 (\u0432 \u0441\u043a\u043e\u0431\u043a\u0430 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432), \u0430 \u0434\u0430\u043b\u0435\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 (<code>primary_key=True<\/code>) \u0438\u043b\u0438 \u043d\u0435\u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043f\u0443\u0441\u0442\u043e\u0433\u043e \u043f\u043e\u043b\u044f email (<code>nullable=False<\/code>) (\u0441\u0442\u0440\u043e\u0447\u043a\u0438 9-11), \u0437\u0430\u0442\u0435\u043c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 <code>__repr__<\/code>, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0435\u0433\u043e \u0437\u0430 \u0444\u043e\u0440\u043c\u0430\u0442 \u0432\u044b\u0432\u043e\u0434\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431 \u043e\u0431\u044a\u0435\u043a\u0442\u0435 \u043a\u043b\u0430\u0441\u0441\u0430(\u0441\u0442\u0440\u043e\u043a\u0438 13-14).<\/p>\n<p>\u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e, \u043e\u0434\u043d\u0430\u043a\u043e \u043f\u043e\u0441\u043b\u0435 \u00ab\u043a\u043e\u043f\u0438-\u043f\u0430\u0441\u0442\u0430\u00bb \u0443 \u043c\u0435\u043d\u044f \u043d\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u043e\u0441\u044c \u0434\u0430\u043d\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435. \u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0441\u0435\u0430\u043d\u0441\u0430, \u044f, \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043b \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0443\u043b\u044f <code>db<\/code> (\u044f \u043d\u0430\u0437\u0432\u0430\u043b \u043c\u043e\u0434\u0443\u043b\u044c <code>model.py<\/code>):<\/p>\n<pre><code class=\"python\">>>> from model import db<\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u043f\u043e\u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0431\u0430\u0437\u0443:<\/p>\n<pre><code class=\"python\">>>> db.create_all()<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0437\u0434\u0435\u0441\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u044e \u043e\u0448\u0438\u0431\u043a\u0443\u2026 \u042f \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0443 \u0432\u044b\u0437\u043e\u0432\u0430, \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0438\u0434\u0430:<\/p>\n<pre><code class=\"python\">sqlite3.OperationalError: unable to open database file<\/code><\/pre>\n<p>\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0438\u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u0430 \u0432 \u0444\u0430\u0439\u043b\u0435 \u0438\u043b\u0438 \u0432 \u043f\u0443\u0442\u0438 \u043a \u043d\u0435\u043c\u0443, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0432\u0442\u043e\u0440\u043e\u0435. \u041f\u043e\u043f\u043b\u044f\u0441\u0430\u0432 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441 \u0431\u0443\u0431\u043d\u0430\u043c\u0438, \u043f\u043e\u043f\u044b\u0442\u0430\u043b\u0441\u044f \u043f\u043e\u0444\u0438\u043a\u0441\u0438\u0441\u0438\u0442\u044c, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u043b \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e, \u043d\u043e \u0442\u0449\u0435\u0442\u043d\u043e. <\/p>\n<p>\u0425\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043d\u0430 <em>MacOS<\/em> \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0440\u0435\u0448\u0438\u043b\u0430\u0441\u044c \u043f\u043e\u0441\u043b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0443\u0442\u0438 \u043a \u0444\u0430\u0439\u043b\u0443 \u0431\u0430\u0437\u044b, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u044f \u0443\u0431\u0440\u0430\u043b \u043e\u0434\u0438\u043d \u0441\u043b\u044d\u0448 \u0438\u0437 \u043f\u0443\u0442\u0438 (\u0442.\u0435. \u044f \u0438\u0437\u043c\u0435\u043d\u0438\u043b <code>'sqlite:\/\/\/\/database.db'<\/code><em> <\/em>\u043d\u0430 <code>'sqlite:\/\/\/database.db'<\/code><em>)<\/em><\/p>\n<p>\u0427\u0442\u043e \u0436, \u0441\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0434\u043b\u044f <em>StackOverflow<\/em>. <a href=\"https:\/\/stackoverflow.com\/questions\/18208492\/sqlalchemy-exc-operationalerror-operationalerror-unable-to-open-database-file\" rel=\"noopener noreferrer nofollow\">\u041f\u0435\u0440\u0432\u0430\u044f \u0436\u0435 \u0441\u0441\u044b\u043b\u043a\u0430<\/a> \u043f\u0440\u043e\u043b\u0438\u0432\u0430\u0435\u0442 \u0441\u0432\u0435\u0442 (\u0443\u0436\u0435 \u043d\u0435 \u0432 \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u0430\u0437 \u0441 \u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u043e\u0435\u0433\u043e \u043f\u0443\u0442\u0438 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438)) \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043a\u043e\u0434\u0438\u0442\u044c \u0432 <em>Windows<\/em> \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e (\u0441\u0443\u0433\u0443\u0431\u043e \u0441\u0443\u0431\u044a\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u043c\u043d\u0435\u043d\u0438\u0435), \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432 \u043f\u0443\u0442\u0438 \u043a \u0444\u0430\u0439\u043b\u0443 \u0431\u044d\u043a\u0441\u043b\u0435\u0448\u0438 (\u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e, \u0447\u0442\u043e \u043c\u043e\u0433 \u043e\u0448\u0438\u0431\u0438\u0442\u044c\u0441\u044f \u0441 \u0432\u044b\u0432\u043e\u0434\u043e\u043c!) \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u044e \u043a\u043e\u0434 \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0442\u0440\u0435\u0434\u0443 \u0438 \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u0438\u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043a\u043e\u0434\u0430:<\/p>\n<pre><code class=\"python\">import os  from flask import Flask from flask_sqlalchemy import SQLAlchemy   file_path = os.path.abspath(os.getcwd()) + \"\\database.db\"  app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:\/\/\/'+file_path db = SQLAlchemy(app)  class User(db.Model):     id = db.Column(db.Integer, primary_key=True)     username = db.Column(db.String(80), unique=True, nullable=False)     email = db.Column(db.String(120), unique=True, nullable=False)          def __repr__(self):         return '&lt;User %r>' % self.username <\/code><\/pre>\n<p>\u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e <a href=\"https:\/\/flask-sqlalchemy.palletsprojects.com\/en\/2.x\/quickstart\/#a-minimal-application\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>, \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"python\">>>> from model import db  >>> db.create_all() >>> from model import User # \u0438\u043c\u043f\u043e\u0440\u0442 \u043a\u043b\u0430\u0441\u0441\u0430-\u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f >>> admin = User(username='admin', email='admin@example.com') # \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 >>> guest = User(username='guest', email='guest@example.com') >>> db.session.add(admin) # \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0432 \u0441\u0435\u0441\u0441\u0438\u044e >>> db.session.add(guest)  >>> db.session.commit() # \u041a\u043e\u043c\u043c\u0438\u0442 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u0435\u0441\u0441\u0438\u0438 \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 >>>User.query.all() # \u0434\u0435\u043b\u0430\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438\u0437 \u0431\u0430\u0437\u044b [&lt;User 'admin'>, &lt;User 'guest'>]<\/code><\/pre>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/strong>: \u0438\u0437-\u0437\u0430 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u043b\u0435\u0439 (<em>unique=True<\/em>), \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u043b\u0435\u0442\u0435\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0437\u0430\u043a\u043e\u043c\u0438\u0442\u0438\u0442\u044c \u0432 \u0431\u0430\u0437\u0443 \u0437\u0430\u043f\u0438\u0441\u0438 \u0441 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u044b\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438. \u0427\u0442\u043e\u0431\u044b \u00ab\u043e\u0442\u043a\u0430\u0442\u0438\u0442\u044c\u00bb \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0441\u0435\u0441\u0441\u0438\u0438 \u0441\u0442\u043e\u0438\u0442 \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c:<\/p>\n<pre><code class=\"python\">>>> db.session.rollback()<\/code><\/pre>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e \u043f\u043e\u043b\u044e, \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u043f\u043e <code>e-mail<\/code>, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>filter_by<\/code>:<\/p>\n<pre><code class=\"python\">>>> User.query.filter_by(email='guest@example.com')<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0430\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 <code>BaseQuery<\/code>, \u0430 \u0442\u043e\u0447\u043d\u0435\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u043d\u0430 \u0435\u0433\u043e \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438:<\/p>\n<pre><code class=\"python\">&lt;flask_sqlalchemy.BaseQuery object at 0x0000000004F80F48><\/code><\/pre>\n<p>\u041f\u0440\u0438 \u044d\u0442\u043e\u043c, \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0438 \u0441\u0430\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 (\u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>first()<\/code>):<\/p>\n<pre><code class=\"python\">>>> User.query.filter_by(email='guest@example.com').first() &lt;User 'guest'><\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 <code>get_or_404()<\/code>:<\/p>\n<pre><code class=\"python\">>>> User.query.get_or_404(ident=1) &lt;User 'admin'> >>> User.query.get_or_404(ident=2) &lt;User 'guest'><\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0438\u0442\u044c \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c, \u0432\u0435\u0440\u043d\u0435\u0442\u0441\u044f 404-\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 (\u043d\u0438\u0436\u0435 \u0431\u0443\u0434\u0443 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c\u0443 \u043e\u0448\u0438\u0431\u043a\u0443, \u0431\u0435\u0437 \u043f\u043e\u043b\u043d\u043e\u0439 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438 \u0432\u044b\u0437\u043e\u0432\u0430): <\/p>\n<pre><code class=\"python\">>>> User.query.get_or_404(ident=3) werkzeug.exceptions.NotFound: 404 Not Found: The requested URL was  not found on the server. If you entered the URL manually please check  your spelling and try again.<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 <code>filter<\/code>, \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u0445\u043e\u0440\u043e\u0448\u043e \u0432\u0438\u0434\u043d\u043e \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435:<\/p>\n<pre><code class=\"python\">>>> User.query.filter(User.email=='guest@example.com').first() &lt;User 'guest'><\/code><\/pre>\n<p>\u0422.\u0435. \u043d\u0430\u0434\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0439 (\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435) \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f (<code>=='guest@example.com'<\/code><em>)<\/em>, \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438 \u043f\u043e\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 (<code>User.email<\/code>). \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0432\u0441\u0435-\u0442\u0430\u043a\u0438, \u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>filter_by<\/code>.<\/p>\n<p>\u0413\u043e\u0442\u043e\u0432\u043e! \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0431\u0430\u0437\u0443 \u0441 \u0434\u0432\u0443\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438.<\/p>\n<h3>\u0414\u0435\u0433\u0443\u0441\u0442\u0430\u0446\u0438\u044f \u0441\u0432\u044f\u0437\u0435\u0439 \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438<\/h3>\n<p>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 <em>Flask<\/em>, \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0432 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0442\u0438\u043f \u043f\u043e\u043b\u044f <code>db.relationship<\/code>. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0435\u0449\u0435 \u0434\u0432\u0430-\u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0438, \u043f\u043e\u0441\u0442\u0430 \u0438 \u0433\u0440\u0443\u043f\u043f (\u0434\u043b\u044f \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0438 \u043f\u043e\u0441\u0442\u043e\u0432):<\/p>\n<pre><code class=\"python\">from datetime import datetime   class Post(db.Model):     id = db.Column(db.Integer, primary_key=True)     author = db.relationship('User', backref=db.backref('posts', lazy=True))     author_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)     title = db.Column(db.String(80), nullable=False)     text = db.Column(db.Text, nullable=False)     pub_date = db.Column(db.DateTime, nullable=False,         default=datetime.utcnow)     group_id = db.Column(db.Integer, db.ForeignKey('group.id'), nullable=False)     group = db.relationship('Group', backref=db.backref('posts', lazy=True))          def __repr__(self):         return '&lt;Post %r>' % self.title class Group(db.Model):     id = db.Column(db.Integer, primary_key=True)     name = db.Column(db.String(50), nullable=False)     description = db.Column(db.Text, nullable=True)          def __repr__(self):         return '&lt;Group %r>' % self.name <\/code><\/pre>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u043e\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0438<em> Post.<\/em> <\/p>\n<p>\u041f\u043e\u043b\u0435 <code>author<\/code><em>, <\/em>\u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043c\u043e\u0434\u0435\u043b\u044c <code>User<\/code><em> <\/em>(\u043f\u0435\u0440\u0432\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442), \u0434\u0430\u043b\u0435\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code>backref<\/code><em> <\/em>(\u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043e\u0442 backreference (\u043e\u0431\u0440\u0430\u0442\u043d\u0430\u044f \u0441\u0432\u044f\u0437\u044c))<em>, <\/em>\u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u043e\u043b\u0435 \u0432 \u043c\u043e\u0434\u0435\u043b\u0438 <code>User<\/code>, c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c <em>posts <\/em>(\u043f\u0435\u0440\u0432\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>db.backref<\/code><em>, <\/em><code>lazy=True<\/code><em>, <\/em>\u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e<em> \u00ab<\/em><code>SQLAlchemy<\/code><em> <\/em>\u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043c\u0435\u0440\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0437\u0430 \u043e\u0434\u0438\u043d \u0440\u0430\u0437, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>select<\/code>\u00bb, \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e <a href=\"https:\/\/flask-sqlalchemy.palletsprojects.com\/en\/2.x\/models\/#one-to-many-relationships\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>. \u0422\u0435 \u0436\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u0441 \u043f\u043e\u043b\u0435\u043c <code>group<\/code>, \u043d\u043e \u0432 \u043c\u0435\u0441\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u0438 <code>User<\/code> \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u043e\u0434\u0435\u043b\u044c <code>Group<\/code>, \u0438 \u0432 \u043d\u0435\u0439 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u043e \u043f\u043e\u043b\u0435 c \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0439 \u0441\u0432\u044f\u0437\u044c\u044e <code>posts<\/code><em>.<\/em><\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043e\u0431\u0440\u0430\u0442\u0438\u043c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043f\u043e\u043b\u0435 <code>group_id<\/code><em>, <\/em>\u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 <code>integer<\/code>, \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0434\u0442\u044f\u0433\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0438\u0437 \u043c\u043e\u0434\u0435\u043b\u0438 (\u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0431\u0430\u0437\u044b)<em> <\/em><code>Group<\/code><em>. <\/em>\u0421\u0432\u044f\u0437\u044c \u0442\u0430\u0431\u043b\u0438\u0446 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>db.ForeignKey()<\/code>.<\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/strong>:<em> <\/em>\u0435\u0441\u043b\u0438 \u0436\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b \u0443\u043a\u0430\u0436\u0435\u0442\u0435 \u0438\u043c\u044f \u043f\u043e\u043b\u044f, \u044d\u0442\u043e\u0439 \u0436\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u043e\u043d\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0442\u044c \u0441 \u0438\u043c\u0435\u043d\u0435\u043c (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u043b\u0435 author \u0432 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u043e\u0441\u0442\u0430), \u0442\u043e\u0433\u0434\u0430 <em>SQLAlchemy <\/em>\u0432\u044b\u0434\u0430\u0441\u0442 \u043e\u0448\u0438\u0431\u043a\u0443 \u0432\u0438\u0434\u0430:<\/p>\n<pre><code class=\"bash\">sqlalchemy.exc.NoReferencedTableError: Foreign key associated with column  'post.author_id' could not find table 'author' with which to generate a  foreign key to target column 'id' <\/code><\/pre>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c \u043d\u0443\u0436\u043d\u044b \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043c\u043e\u0434\u0435\u043b\u044c, \u0447\u0435\u0440\u0435\u0437 \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0435 \u0432\u043e\u0442 \u0441\u0443\u0431-\u043f\u043e\u043b\u0435 (\u0441 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u043c \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0431\u0430\u0437\u044b), \u0447\u0442\u043e\u0431\u044b \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u0435 \u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c\u0438 \u0431\u0430\u0437\u044b. \u0415\u0441\u043b\u0438 \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0432\u044f\u0437\u0438 \u0431\u0435\u0437 \u044d\u0442\u0438\u0445 \u0441\u0443\u0431-\u043f\u043e\u043b\u0435\u0439 (<code>group_id, author_id<\/code>), \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0438\u0434\u0430:<\/p>\n<pre><code class=\"bash\">sqlalchemy.exc.NoForeignKeysError: Could not determine join condition between  parent\/child tables on relationship Post.author - there are no foreign keys  linking these tables.  Ensure that referencing columns are associated with a  ForeignKey or ForeignKeyConstraint, or specify a 'primaryjoin' expression. <\/code><\/pre>\n<p>\u041f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u0432\u044f\u0437\u0438.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0444\u0430\u0439\u043b \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043a\u043e\u0440\u043d\u044f \u0440\u0430\u0431\u043e\u0447\u0435\u0433\u043e \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430. \u041e\u043d \u0431\u044b\u043b \u0441\u043e\u0437\u0434\u0430\u043d \u043f\u0440\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0430 \u0442\u0430\u043a \u043a\u0430\u043a \u0441\u0435\u0439\u0447\u0430\u0441 \u043c\u044b \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0432\u044f\u0437\u0438, \u043c\u043e\u0433\u0443\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u044f \u0441\u0434\u0435\u043b\u0430\u043b \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a, \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 \u044f \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u044e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435, \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043d\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u0431\u0430\u0437\u0443, \u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u0443\u044e.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0430\u0440\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0434\u043b\u044f \u043d\u043e\u0432\u043e\u0439 \u0431\u0430\u0437\u044b:<\/p>\n<pre><code class=\"python\">>>> from models import db >>> db.create_all() >>> from models import User >>> trinity = User(username='trinity', email='trinity@example.com') >>> morpheus = User(username='morpheus', email='morpheus@example.com') >>> db.session.add(trinity) >>> db.session.add(morpheus) >>> db.session.commit() >>> User.query.all() [&lt;User 'trinity'>, &lt;User 'morpheus'>]<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0433\u0440\u0443\u043f\u043f\u044b \u0438 \u043d\u0430\u043f\u043e\u043b\u043d\u0438\u043c \u0435\u0435 \u043f\u043e\u0441\u0442\u0430\u043c\u0438. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043f\u043e\u0441\u0442\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u0433\u0440\u0443\u043f\u043f\u0443 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438. \u041a\u0430\u043a \u0447\u0435\u0440\u0435\u0437 \u043c\u043e\u0434\u0435\u043b\u044c <code>Post<\/code><em>, <\/em>\u0442\u0430\u043a \u0438 \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0441\u0442\u043e\u0432 \u0432 \u043f\u043e\u043b\u0435 <code>posts<\/code><em> <\/em>\u0433\u0440\u0443\u043f\u043f\u044b <code>matrix<\/code>:<\/p>\n<pre><code class=\"python\">>>> from models import Post, Group >>> matrix = Group(name='Matrix') >>> Post(title='Wake up', text='Wake up, Neo...', author=trinity, group=matrix) # \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0447\u0435\u0440\u0435\u0437 \u043c\u043e\u0434\u0435\u043b\u044c &lt;Post 'Wake up'> >>> p1 = Post(title='Truth', text='You are a slave, Neo', author=morpheus) >>> p2 = Post(title='Secret', text='Open your mind', author=morpheus) >>> matrix.posts.append(p1) # \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0441\u0442\u0430 \u0441\u0440\u0430\u0437\u0443 \u0432 posts >>> matrix.posts.append(p2) >>> db.session.add(matrix) >>> matrix.posts [&lt;Post 'Wake up'>, &lt;Post 'Truth'>, &lt;Post 'Secret'>]<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u043e\u0441\u0442 \u0432 \u0441\u0435\u0441\u0441\u0438\u044e, \u0442\u0430\u043a \u043a\u0430\u043a \u0433\u0440\u0443\u043f\u043f\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u0441\u0435\u0441\u0441\u0438\u0438, \u0442\u043e \u0447\u0435\u0440\u0435\u0437 \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f, \u0432\u0441\u0435 \u043f\u043e\u0441\u0442\u044b, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u0433\u0440\u0443\u043f\u043f\u043e\u0439, \u0431\u0443\u0434\u0443\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u0432 \u0441\u0435\u0441\u0441\u0438\u044e.<\/p>\n<p>\u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 <a href=\"https:\/\/flask-sqlalchemy.palletsprojects.com\/en\/2.x\/quickstart\/#simple-relationships\" rel=\"noopener noreferrer nofollow\">Flask-SQLAlchemy<\/a>, \u0442\u0430\u043a \u043a\u0430\u043a \u0432 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f\u0445 \u0432\u044b\u0431\u0440\u0430\u043d\u0430 \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u0430\u044f \u00ab\u043b\u0435\u043d\u0438\u0432\u0430\u044f\u00bb \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0441\u0432\u044f\u0437\u044f\u043c, \u0442\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 (\u0432 \u043f\u043b\u0430\u043d\u0435 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438) \u043f\u0440\u0438 \u043f\u043e\u0434\u0433\u0440\u0443\u0437\u043a\u0435 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u0430\u043f\u0438\u0441\u0435\u0439, \u043e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c. <em>SQLAlchemy<\/em> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044e \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0432\u0441\u0435\u0445 \u0433\u0440\u0443\u043f\u043f \u0438 \u0438\u0445 \u043f\u043e\u0441\u0442\u043e\u0432 \u0437\u0430 \u043e\u0434\u0438\u043d \u0437\u0430\u043f\u0440\u043e\u0441, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u0438\u0436\u0435:<\/p>\n<pre><code class=\"python\">>>> from sqlalchemy.orm import joinedload >>> query = Group.query.options(joinedload('posts')) >>> for group in query: ...     print(group, group.posts) &lt;Group 'Matrix'> [&lt;Post 'Wake up'>, &lt;Post 'Truth'>, &lt;Post 'Secret'>]<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 <code>query<\/code><em> <\/em>\u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0432\u044f\u0437\u0438, \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>with_parent()<\/code>:<\/p>\n<pre><code class=\"python\">>>> Post.query.with_parent(matrix).filter(Post.title != 'Truth').all() [&lt;Post 'Wake up'>, &lt;Post 'Secret'>]<\/code><\/pre>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u044f \u043f\u043e\u043a\u0430 \u043f\u0440\u0435\u0440\u0432\u0443 \u0441\u0432\u043e\u0439 \u0440\u0430\u0441\u0441\u043a\u0430\u0437, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442\u0441\u044f, \u044f \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u044e \u0434\u0430\u043b\u044c\u0448\u0435 \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u0442\u044c\u0441\u044f \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u043f\u0443\u0442\u044c \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f <em>Flask<\/em>. \u041d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442, \u043a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0438\u0437 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u0448\u0435, \u0432\u0441\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0432 \u0443\u0441\u0432\u043e\u0435\u043d\u0438\u0438, \u043d\u043e \u043a\u0430\u043a \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c\u0441\u044f: \u00ab\u0414\u044c\u044f\u0432\u043e\u043b \u043a\u0440\u043e\u0435\u0442\u0441\u044f \u0432 \u0434\u0435\u0442\u0430\u043b\u044f\u0445\u00bb, \u0431\u0443\u0434\u0443 \u043d\u0430\u0434\u0435\u0435\u0442\u0441\u044f, <em>Flask<\/em> \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c.<\/p>\n<p>\u00abFollow the white rabbit.\u00bb<\/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\/680180\/\"> https:\/\/habr.com\/ru\/articles\/680180\/<\/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 \u0434\u043e\u0431\u0440\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0443\u0442\u043e\u043a. \u0412 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0434\u0432\u0430 \u0433\u043e\u0434\u0430 \u043d\u0430\u0437\u0430\u0434 \u044f \u0431\u044b\u043b \u043f\u0440\u043e\u0444\u0430\u043d, \u0438 \u043d\u0430\u0447\u0430\u043b \u0441 <em>Python<\/em>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0441 \u044d\u0442\u0438\u043c \u044f\u0437\u044b\u043a\u043e\u043c \u0431\u044b\u043b\u0430 \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u043c\u043e\u044f \u0434\u0438\u0441\u0441\u0435\u0440\u0442\u0430\u0446\u0438\u044f, \u043d\u043e \u043f\u043e\u043d\u044f\u043b, \u0447\u0442\u043e \u043d\u0435 \u0442\u044f\u043d\u0443 \u0432 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0438 \u0441\u0430\u043c \u0438 \u043f\u043e\u0448\u0435\u043b \u043d\u0430 \u043a\u0443\u0440\u0441\u044b, \u0433\u0434\u0435 \u043d\u0430\u0443\u0447\u0438\u043b\u0438 \u043e\u0441\u043d\u043e\u0432\u0430\u043c <em>Python<\/em>, \u043a\u0430\u043a \u0434\u0435\u043b\u0430\u0442\u044c \u0431\u043b\u043e\u0433-\u0441\u043e\u0446\u0441\u0435\u0442\u044c \u043d\u0430 <em>Django<\/em>, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 <em>API<\/em>, \u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e DevOps. \u041d\u043e \u043a\u0443\u0440\u0441\u044b \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438\u0441\u044c, \u0438 \u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441, \u00ab\u0447\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435?\u00bb. \u041f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u043c \u044f \u043d\u0435 \u043c\u043e\u0433\u0443 \u0441\u043c\u0435\u043d\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443, \u043d\u043e \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0445\u0432\u0430\u0442\u0430\u0435\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043b \u041b\u0443\u0442\u0446\u0430, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0434\u0442\u044f\u043d\u0443\u0442\u044c \u00ab\u043c\u0430\u0442\u0447\u0430\u0441\u0442\u044c\u00bb, \u0437\u0430\u0442\u0435\u043c \u00ab\u0427\u0438\u0441\u0442\u044b\u0439 \u043a\u043e\u0434\u00bb \u0420\u043e\u0431\u0435\u0440\u0442\u0430 \u041c\u0430\u0440\u0442\u0438\u043d\u0430. C\u0434\u0435\u043b\u0430\u043b \u043f\u0430\u0440\u043e\u0447\u043a\u0443 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u043d\u0430 <em>Django<\/em>, \u043e\u0434\u0438\u043d <em>API<\/em>, \u043f\u043e\u0443\u0447\u0438\u043b <em>JS<\/em>. \u0418 \u0441\u043d\u043e\u0432\u0430 \u0432\u043e\u0437\u043d\u0438\u043a \u0432\u043e\u043f\u0440\u043e\u0441, \u00ab\u0447\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435?\u00bb \u0411\u044b\u043b\u043e \u0434\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 <em>FastAPI<\/em> \u0438 <em>Flask<\/em>. \u0412\u044b\u0431\u043e\u0440 \u043f\u0430\u043b \u043d\u0430 <em>Flask<\/em>.<\/p>\n<p>\u0425\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043a\u0430\u043a \u0431\u044b \u0431\u043e\u0440\u0442\u043e\u0432\u043e\u0439 \u0436\u0443\u0440\u043d\u0430\u043b \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u0436\u0443\u043d\u043e\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e, \u0447\u0442\u043e \u043c\u0435\u0441\u0442\u0430\u043c\u0438 \u043c\u043e\u0433 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438. \u042f \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u0442\u043a\u0440\u044b\u0442 \u0434\u043b\u044f \u043a\u0440\u0438\u0442\u0438\u043a\u0438, \u043c\u043e\u044f \u0446\u0435\u043b\u044c \u2013 \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0438\u0441\u044c\u043c\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u0435\u0439, \u00a0\u0442\u0430\u043a \u043a\u0430\u043a \u0434\u0430\u043d\u043d\u0430\u044f (\u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442\u0441\u044f \ud83d\ude42 ) \u0431\u0443\u0434\u0435\u0442 \u0434\u0435\u0431\u044e\u0442\u043e\u043c.<\/p>\n<h3>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430<\/h3>\n<p>\u0421 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u043e\u0439 \u0432\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e. <\/p>\n<ol>\n<li>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0435 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 <code>venv<\/code><\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">py \u2013m venv venv # \u0438\u043b\u0438  python \u2013m venv venv # \u0438\u043b\u0438  python3 \u2013m venv venv<\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0435 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\"># Windows: source venv\/Scripts\/activate # \u0438\u043b\u0438 .\\venv\\Scripts\\activate # MacOS\/Ubuntu: source venv\/bin\/activate<\/code><\/pre>\n<ol start=\"3\">\n<li>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c <em>Flask<\/em> (\u0432\u0441\u0435 \u043d\u0443\u0436\u043d\u044b\u0435 \u043f\u0430\u043a\u0435\u0442\u044b <em>Flask<\/em> \u043f\u043e\u0434\u0442\u044f\u043d\u0435\u0442 \u0441\u0430\u043c):<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">pip install flask<\/code><\/pre>\n<p>\u0412\u0441\u0435 \u0433\u043e\u0442\u043e\u0432\u043e! \u0414\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u044d\u0442\u043e \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u043e \u0432 <a href=\"https:\/\/flask.palletsprojects.com\/en\/2.1.x\/installation\/\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a> .<\/p>\n<h3>Wake up, Neo\u2026<\/h3>\n<p>\u0414\u0435\u043b\u0430\u0435\u043c \u0441\u0430\u043c\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 \u0441\u0432\u0435\u0442\u0435.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b \u0432 \u0440\u0430\u0431\u043e\u0447\u0435\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0438 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u043a\u0430\u043a \u0443\u0433\u043e\u0434\u043d\u043e. \u041d\u0443\u0443\u0443, \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c, \u043a\u0430\u043a \u0443\u0433\u043e\u0434\u043d\u043e, \u0435\u0441\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0438\u043c\u0435\u043d\u0438 \u0444\u0430\u0439\u043b\u0430, \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0430\u044e\u0442, \u0447\u0442\u043e \u043d\u0435\u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0438\u043c\u044f \u0444\u0430\u0439\u043b\u0430 <code>flask.py<\/code>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442 \u0438\u043c\u0435\u043d \u0441 <em>Flask<\/em>.<\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043a\u043b\u0430\u0441\u0441 <code>Flask<\/code> \u0438\u0437 \u043c\u043e\u0434\u0443\u043b\u044f <code>flask<\/code><\/p>\n<pre><code class=\"python\">from flask import Flask<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u0421\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 (<code>app<\/code>) \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0448\u0438\u043c <abbr title=\"Web Server Gateway Interface\" type=\"abbr\">WSGI<\/abbr>-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c(\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0432 <a href=\"https:\/\/peps.python.org\/pep-3333\/\" rel=\"noopener noreferrer nofollow\">PEP 3333<\/a>).<\/p>\n<pre><code class=\"python\">app = Flask(__name__)<\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>__name__<\/code>, \u0432 \u043d\u0435\u0439 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0438\u043c\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043f\u043e\u0437\u0436\u0435, \u0430 \u043f\u043e\u043a\u0430 \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438: \u00ab<code>__name__<\/code> \u2014 \u044d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e\u0435 \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u0441\u043b\u0443\u0447\u0430\u0435\u0432. \u042d\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b <em>Flask<\/em> \u0437\u043d\u0430\u043b, \u0433\u0434\u0435 \u0438\u0441\u043a\u0430\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441\u044b, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u0448\u0430\u0431\u043b\u043e\u043d\u044b(<em>templates<\/em>) \u0438 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0444\u0430\u0439\u043b\u044b.\u00bb<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443:<\/p>\n<pre><code class=\"python\">def wake_up():     return 'Wake up, Neo...'<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0448\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u043e\u0431\u0449\u0438\u0442\u044c <em>Flask<\/em>, \u043f\u0440\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043a\u0430\u043a\u043e\u0433\u043e <em>URL<\/em>, \u0434\u043e\u043b\u0436\u043d\u0430 \u00ab\u0441\u0442\u0440\u0438\u0433\u0435\u0440\u0438\u0442\u044c\u0441\u044f\u00bb (\u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c\u0441\u044f) \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>wake_up<\/code>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0443 <em>Flask<\/em> \u0435\u0441\u0442\u044c \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 <code>route<\/code>:<\/p>\n<pre><code>@app.route('\/') def wake_up():     return 'Wake up, Neo...'<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u0432 \u043a\u043e\u0440\u0435\u043d\u044c \u0432\u044d\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u00ab<em>Wake up, Neo&#8230;<\/em>\u00bb.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435. \u0414\u043b\u044f \u0442\u0435\u0441\u0442\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440, \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c (\u0437\u0434\u0435\u0441\u044c \u0438 \u0434\u0430\u043b\u0435\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u0432\u0435\u0440\u0441\u0438\u0438 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f <em>Windows<\/em>).<\/p>\n<ol>\n<li>\n<p>\u0413\u043e\u0432\u043e\u0440\u0438\u043c \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0443, \u0441 \u043a\u0430\u043a\u0438\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c (\u0432 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0444\u0430\u0439\u043b \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>start.py<\/code>, \u043e\u0434\u043d\u0430\u043a\u043e \u0435\u0441\u043b\u0438 \u0444\u0430\u0439\u043b \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>app.py<\/code> \u0438\u043b\u0438 <code>wsgi.py<\/code>, \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u043d\u0435\u0442 \u043d\u0443\u0436\u0434\u044b \u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u0448\u0430\u0433, \u0442.\u043a. <em>Flask<\/em> \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u044d\u0442\u0438 \u0444\u0430\u0439\u043b\u044b \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c), \u043f\u0443\u0442\u0435\u043c \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f <code>FLASK_APP<\/code>:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">export FLASK_APP=start.py<\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p>\u0412\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0432\u0441\u0435 \u0444\u0438\u0447\u0438 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 (\u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0438 \u0434\u0435\u0431\u0430\u0433\u0435\u0440), \u043f\u0443\u0442\u0435\u043c \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f <code>FLASK_ENV<\/code>:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">export FLASK_ENV=development<\/code><\/pre>\n<ol start=\"3\">\n<li>\n<p>\u0418 \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u0435\u0440\u0432\u0435\u0440:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">flask run<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0432\u0432\u043e\u0434\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b <em>Flask<\/em> \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440, \u0430\u0434\u0440\u0435\u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043e\u0431\u044b\u0447\u043d\u043e <a href=\"http:\/\/127.0.0.1:5000\" rel=\"noopener noreferrer nofollow\">http:\/\/127.0.0.1:5000<\/a>. \u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u0430\u0434\u0440\u0435\u0441\u0443. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u0443\u0441\u0442\u0430\u044f \u0432\u044d\u0431-\u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043a\u0430 \u0441 \u043d\u0430\u0434\u043f\u0438\u0441\u044c\u044e <em>\u00abWake up, Neo\u2026\u00bb<\/em>.<\/p>\n<p>\u041d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435. \u041c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0447\u0435\u0440\u0435\u0437 \u0442\u043e\u0447\u043a\u0443 \u0432\u0445\u043e\u0434\u0430, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 \u043a\u043e\u043d\u0446\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"python\">if __name__ == \"__main__\":     app.run(debug=True)<\/code><\/pre>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0435\u0440\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u044d\u0442\u0438\u043c \u0437\u0430\u0442\u0440\u0443\u0434\u043d\u0435\u043d\u0438\u044f<\/h3>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0432\u043f\u043e\u043b\u043d\u0435 \u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u043c\u043e\u0434\u0435\u043b\u044f\u043c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 <em>Flask<\/em>, \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 <em>SQLAlchemy<\/em> (\u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u0430\u044f \u0441\u0432\u044f\u0437\u043a\u0430). \u0414\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435:<\/p>\n<pre><code class=\"bash\">pip install -U Flask-SQLAlchemy<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0432\u043e <em>Flask<\/em>, \u044f \u043e\u0431\u0440\u0430\u0442\u0438\u043b\u0441\u044f \u043a <a href=\"https:\/\/flask-sqlalchemy.palletsprojects.com\/en\/2.x\/\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Flask-SQLAlchemy<\/a>.<\/p>\n<p>\u0412 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 <a href=\"https:\/\/flask-sqlalchemy.palletsprojects.com\/en\/2.x\/quickstart\/\" rel=\"noopener noreferrer nofollow\">Quickstart <\/a>\u0435\u0441\u0442\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043b\u044f \u0440\u0430\u0437\u0431\u043e\u0440\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0435\u0433\u043e \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e, \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"python\">from flask import Flask from flask_sqlalchemy import SQLAlchemy  app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:\/\/\/\/database.db' db = SQLAlchemy(app)  class User(db.Model):     id = db.Column(db.Integer, primary_key=True)     username = db.Column(db.String(80), unique=True, nullable=False)     email = db.Column(db.String(120), unique=True, nullable=False)          def __repr__(self):         return '&lt;User %r>' % self.username<\/code><\/pre>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a <code>flask<\/code><em> <\/em>\u0438 <code>flask_sqlalchemy<\/code><em> <\/em>(\u043f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0435 \u0441\u0442\u0440\u043e\u0447\u043a\u0438), \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 (\u0441\u0442\u0440\u043e\u0447\u043a\u0430 4), \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0441 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0435\u0439 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 (\u0441\u0442\u0440\u043e\u0447\u043a\u0430 5), \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 <code>SQLAlchemy<\/code><em> (\u00ab<\/em>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0435\u0439 <em>SQLAlchemy<\/em> \u0432 \u043e\u0434\u043d\u043e \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 <em>Flask\u00bb)<\/em> \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0435\u043c\u0443 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f <code>Flask<\/code> (\u0441\u0442\u0440\u043e\u0447\u043a\u0430 6), \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441-\u043c\u043e\u0434\u0435\u043b\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (\u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c\u0441\u044f \u043e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 <code>SQLAlchemy<\/code>) (\u0441\u0442\u0440\u043e\u0447\u043a\u0430 8), \u0434\u0430\u043b\u0435\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u043e\u043b\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b (\u043c\u043e\u0434\u0435\u043b\u0438) c \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043b\u0430\u0441\u0441\u0430 <code>Column<\/code>, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441 \u0442\u0438\u043f\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 (\u0432 \u0441\u043a\u043e\u0431\u043a\u0430 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432), \u0430 \u0434\u0430\u043b\u0435\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 (<code>primary_key=True<\/code>) \u0438\u043b\u0438 \u043d\u0435\u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043f\u0443\u0441\u0442\u043e\u0433\u043e \u043f\u043e\u043b\u044f email (<code>nullable=False<\/code>) (\u0441\u0442\u0440\u043e\u0447\u043a\u0438 9-11), \u0437\u0430\u0442\u0435\u043c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 <code>__repr__<\/code>, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0435\u0433\u043e \u0437\u0430 \u0444\u043e\u0440\u043c\u0430\u0442 \u0432\u044b\u0432\u043e\u0434\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431 \u043e\u0431\u044a\u0435\u043a\u0442\u0435 \u043a\u043b\u0430\u0441\u0441\u0430(\u0441\u0442\u0440\u043e\u043a\u0438 13-14).<\/p>\n<p>\u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e, \u043e\u0434\u043d\u0430\u043a\u043e \u043f\u043e\u0441\u043b\u0435 \u00ab\u043a\u043e\u043f\u0438-\u043f\u0430\u0441\u0442\u0430\u00bb \u0443 \u043c\u0435\u043d\u044f \u043d\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u043e\u0441\u044c \u0434\u0430\u043d\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435. \u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0441\u0435\u0430\u043d\u0441\u0430, \u044f, \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043b \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0443\u043b\u044f <code>db<\/code> (\u044f \u043d\u0430\u0437\u0432\u0430\u043b \u043c\u043e\u0434\u0443\u043b\u044c <code>model.py<\/code>):<\/p>\n<pre><code class=\"python\">>>> from model import db<\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u043f\u043e\u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0431\u0430\u0437\u0443:<\/p>\n<pre><code class=\"python\">>>> db.create_all()<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0437\u0434\u0435\u0441\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u044e \u043e\u0448\u0438\u0431\u043a\u0443\u2026 \u042f \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0443 \u0432\u044b\u0437\u043e\u0432\u0430, \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0438\u0434\u0430:<\/p>\n<pre><code class=\"python\">sqlite3.OperationalError: unable to open database file<\/code><\/pre>\n<p>\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0438\u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u0430 \u0432 \u0444\u0430\u0439\u043b\u0435 \u0438\u043b\u0438 \u0432 \u043f\u0443\u0442\u0438 \u043a \u043d\u0435\u043c\u0443, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0432\u0442\u043e\u0440\u043e\u0435. \u041f\u043e\u043f\u043b\u044f\u0441\u0430\u0432 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441 \u0431\u0443\u0431\u043d\u0430\u043c\u0438, \u043f\u043e\u043f\u044b\u0442\u0430\u043b\u0441\u044f \u043f\u043e\u0444\u0438\u043a\u0441\u0438\u0441\u0438\u0442\u044c, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u043b \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e, \u043d\u043e \u0442\u0449\u0435\u0442\u043d\u043e. <\/p>\n<p>\u0425\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043d\u0430 <em>MacOS<\/em> \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0440\u0435\u0448\u0438\u043b\u0430\u0441\u044c \u043f\u043e\u0441\u043b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0443\u0442\u0438 \u043a \u0444\u0430\u0439\u043b\u0443 \u0431\u0430\u0437\u044b, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u044f \u0443\u0431\u0440\u0430\u043b \u043e\u0434\u0438\u043d \u0441\u043b\u044d\u0448 \u0438\u0437 \u043f\u0443\u0442\u0438 (\u0442.\u0435. \u044f \u0438\u0437\u043c\u0435\u043d\u0438\u043b <code>'sqlite:\/\/\/\/database.db'<\/code><em> <\/em>\u043d\u0430 <code>'sqlite:\/\/\/database.db'<\/code><em>)<\/em><\/p>\n<p>\u0427\u0442\u043e \u0436, \u0441\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0434\u043b\u044f <em>StackOverflow<\/em>. <a href=\"https:\/\/stackoverflow.com\/questions\/18208492\/sqlalchemy-exc-operationalerror-operationalerror-unable-to-open-database-file\" rel=\"noopener noreferrer nofollow\">\u041f\u0435\u0440\u0432\u0430\u044f \u0436\u0435 \u0441\u0441\u044b\u043b\u043a\u0430<\/a> \u043f\u0440\u043e\u043b\u0438\u0432\u0430\u0435\u0442 \u0441\u0432\u0435\u0442 (\u0443\u0436\u0435 \u043d\u0435 \u0432 \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u0430\u0437 \u0441 \u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u043e\u0435\u0433\u043e \u043f\u0443\u0442\u0438 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438)) \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043a\u043e\u0434\u0438\u0442\u044c \u0432 <em>Windows<\/em> \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e (\u0441\u0443\u0433\u0443\u0431\u043e \u0441\u0443\u0431\u044a\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u043c\u043d\u0435\u043d\u0438\u0435), \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432 \u043f\u0443\u0442\u0438 \u043a \u0444\u0430\u0439\u043b\u0443 \u0431\u044d\u043a\u0441\u043b\u0435\u0448\u0438 (\u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e, \u0447\u0442\u043e \u043c\u043e\u0433 \u043e\u0448\u0438\u0431\u0438\u0442\u044c\u0441\u044f \u0441 \u0432\u044b\u0432\u043e\u0434\u043e\u043c!) \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u044e \u043a\u043e\u0434 \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0442\u0440\u0435\u0434\u0443 \u0438 \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u0438\u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043a\u043e\u0434\u0430:<\/p>\n<pre><code class=\"python\">import os  from flask import Flask from flask_sqlalchemy import SQLAlchemy   file_path = os.path.abspath(os.getcwd()) + \"\\database.db\"  app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:\/\/\/'+file_path db = SQLAlchemy(app)  class User(db.Model):     id = db.Column(db.Integer, primary_key=True)     username = db.Column(db.String(80), unique=True, nullable=False)     email = db.Column(db.String(120), unique=True, nullable=False)          def __repr__(self):         return '&lt;User %r>' % self.username <\/code><\/pre>\n<p>\u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e <a href=\"https:\/\/flask-sqlalchemy.palletsprojects.com\/en\/2.x\/quickstart\/#a-minimal-application\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>, \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"python\">>>> from model import db  >>> db.create_all() >>> from model import User # \u0438\u043c\u043f\u043e\u0440\u0442 \u043a\u043b\u0430\u0441\u0441\u0430-\u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f >>> admin = User(username='admin', email='admin@example.com') # \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 >>> guest = User(username='guest', email='guest@example.com') >>> db.session.add(admin) # \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0432 \u0441\u0435\u0441\u0441\u0438\u044e >>> db.session.add(guest)  >>> db.session.commit() # \u041a\u043e\u043c\u043c\u0438\u0442 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u0435\u0441\u0441\u0438\u0438 \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 >>>User.query.all() # \u0434\u0435\u043b\u0430\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438\u0437 \u0431\u0430\u0437\u044b [&lt;User 'admin'>, &lt;User 'guest'>]<\/code><\/pre>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/strong>: \u0438\u0437-\u0437\u0430 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u043b\u0435\u0439 (<em>unique=True<\/em>), \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u043b\u0435\u0442\u0435\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0437\u0430\u043a\u043e\u043c\u0438\u0442\u0438\u0442\u044c \u0432 \u0431\u0430\u0437\u0443 \u0437\u0430\u043f\u0438\u0441\u0438 \u0441 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u044b\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438. \u0427\u0442\u043e\u0431\u044b \u00ab\u043e\u0442\u043a\u0430\u0442\u0438\u0442\u044c\u00bb \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0441\u0435\u0441\u0441\u0438\u0438 \u0441\u0442\u043e\u0438\u0442 \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c:<\/p>\n<pre><code class=\"python\">>>> db.session.rollback()<\/code><\/pre>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e \u043f\u043e\u043b\u044e, \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u043f\u043e <code>e-mail<\/code>, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>filter_by<\/code>:<\/p>\n<pre><code class=\"python\">>>> User.query.filter_by(email='guest@example.com')<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0430\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 <code>BaseQuery<\/code>, \u0430 \u0442\u043e\u0447\u043d\u0435\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u043d\u0430 \u0435\u0433\u043e \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438:<\/p>\n<pre><code class=\"python\">&lt;flask_sqlalchemy.BaseQuery object at 0x0000000004F80F48><\/code><\/pre>\n<p>\u041f\u0440\u0438 \u044d\u0442\u043e\u043c, \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0438 \u0441\u0430\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 (\u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>first()<\/code>):<\/p>\n<pre><code class=\"python\">>>> User.query.filter_by(email='guest@example.com').first() &lt;User 'guest'><\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 <code>get_or_404()<\/code>:<\/p>\n<pre><code class=\"python\">>>> User.query.get_or_404(ident=1) &lt;User 'admin'> >>> User.query.get_or_404(ident=2) &lt;User 'guest'><\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0438\u0442\u044c \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c, \u0432\u0435\u0440\u043d\u0435\u0442\u0441\u044f 404-\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 (\u043d\u0438\u0436\u0435 \u0431\u0443\u0434\u0443 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c\u0443 \u043e\u0448\u0438\u0431\u043a\u0443, \u0431\u0435\u0437 \u043f\u043e\u043b\u043d\u043e\u0439 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438 \u0432\u044b\u0437\u043e\u0432\u0430): <\/p>\n<pre><code class=\"python\">>>> User.query.get_or_404(ident=3) werkzeug.exceptions.NotFound: 404 Not Found: The requested URL was  not found on the server. If you entered the URL manually please check  your spelling and try again.<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 <code>filter<\/code>, \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u0445\u043e\u0440\u043e\u0448\u043e \u0432\u0438\u0434\u043d\u043e \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435:<\/p>\n<pre><code class=\"python\">>>> User.query.filter(User.email=='guest@example.com').first() &lt;User 'guest'><\/code><\/pre>\n<p>\u0422.\u0435. \u043d\u0430\u0434\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0439 (\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435) \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f (<code>=='guest@example.com'<\/code><em>)<\/em>, \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438 \u043f\u043e\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 (<code>User.email<\/code>). \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0432\u0441\u0435-\u0442\u0430\u043a\u0438, \u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>filter_by<\/code>.<\/p>\n<p>\u0413\u043e\u0442\u043e\u0432\u043e! \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0431\u0430\u0437\u0443 \u0441 \u0434\u0432\u0443\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438.<\/p>\n<h3>\u0414\u0435\u0433\u0443\u0441\u0442\u0430\u0446\u0438\u044f \u0441\u0432\u044f\u0437\u0435\u0439 \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438<\/h3>\n<p>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 <em>Flask<\/em>, \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0432 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0442\u0438\u043f \u043f\u043e\u043b\u044f <code>db.relati<\/code><\/p>\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-416249","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/416249","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=416249"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/416249\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=416249"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=416249"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=416249"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}