{"id":92812,"date":"2026-08-11T11:16:57","date_gmt":"2026-08-11T03:16:57","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/92812.html"},"modified":"2026-08-11T11:16:57","modified_gmt":"2026-08-11T03:16:57","slug":"flask-%e6%a0%b8%e5%bf%83%e9%80%9f%e6%9f%a5%e4%b8%8e%e5%ae%9e%e6%88%98%e6%89%8b%e5%86%8c","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/92812.html","title":{"rendered":"Flask \u6838\u5fc3\u901f\u67e5\u4e0e\u5b9e\u6218\u624b\u518c"},"content":{"rendered":"<hr \/>\n<h3>1. \u5feb\u901f\u542f\u52a8\u4e0e\u73af\u5883\u914d\u7f6e<\/h3>\n<h4>1.1 \u865a\u62df\u73af\u5883&#xff08;\u5fc5\u9009&#xff09;<\/h4>\n<p><span class=\"token comment\"># \u521b\u5efa<\/span><br \/>\npython <span class=\"token parameter variable\">-m<\/span> venv venv<\/p>\n<p><span class=\"token comment\"># \u6fc0\u6d3b (Windows)<\/span><br \/>\nvenv<span class=\"token punctuation\">\\\\<\/span>Scripts<span class=\"token punctuation\">\\\\<\/span>activate<br \/>\n<span class=\"token comment\"># \u6fc0\u6d3b (Mac\/Linux)<\/span><br \/>\n<span class=\"token builtin class-name\">source<\/span> venv\/bin\/activate<\/p>\n<p><span class=\"token comment\"># \u5b89\u88c5<\/span><br \/>\npip <span class=\"token function\">install<\/span> flask<\/p>\n<h4>1.2 \u6700\u5c0f\u5e94\u7528\u7ed3\u6784<\/h4>\n<p><span class=\"token keyword\">from<\/span> flask <span class=\"token keyword\">import<\/span> Flask<\/p>\n<p>app <span class=\"token operator\">&#061;<\/span> Flask<span class=\"token punctuation\">(<\/span>__name__<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token decorator annotation punctuation\">&#064;app<span class=\"token punctuation\">.<\/span>route<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\/&#039;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">def<\/span> <span class=\"token function\">index<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;Hello, Flask!&#034;<\/span><\/p>\n<p><span class=\"token keyword\">if<\/span> __name__ <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token string\">&#039;__main__&#039;<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token comment\"># \u751f\u4ea7\u73af\u5883\u8bf7\u52ff\u4f7f\u7528 debug&#061;True<\/span><br \/>\n    app<span class=\"token punctuation\">.<\/span>run<span class=\"token punctuation\">(<\/span>debug<span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">True<\/span><span class=\"token punctuation\">,<\/span> port<span class=\"token operator\">&#061;<\/span><span class=\"token number\">5000<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<h4>1.3 \u914d\u7f6e\u7ba1\u7406<\/h4>\n<p>\u63a8\u8350\u4f7f\u7528\u5de5\u5382\u6a21\u5f0f &#043; \u73af\u5883\u53d8\u91cf&#xff1a;<\/p>\n<p><span class=\"token keyword\">import<\/span> os<br \/>\n<span class=\"token keyword\">from<\/span> flask <span class=\"token keyword\">import<\/span> Flask<\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">create_app<\/span><span class=\"token punctuation\">(<\/span>config_name<span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">None<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    app <span class=\"token operator\">&#061;<\/span> Flask<span class=\"token punctuation\">(<\/span>__name__<span class=\"token punctuation\">)<\/span><br \/>\n    config_map <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token string\">&#039;dev&#039;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#039;config.DevelopmentConfig&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        <span class=\"token string\">&#039;prod&#039;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#039;config.ProductionConfig&#039;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    app<span class=\"token punctuation\">.<\/span>config<span class=\"token punctuation\">.<\/span>from_object<span class=\"token punctuation\">(<\/span>config_map<span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span>config_name<span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;config.DevelopmentConfig&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> app<\/p>\n<hr \/>\n<h3>2. \u8def\u7531\u4e0e\u8bf7\u6c42\u5904\u7406<\/h3>\n<h4>2.1 \u8def\u7531\u6838\u5fc3<\/h4>\n<table>\n<tr>\u7279\u6027\u793a\u4f8b\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td align=\"left\">\u52a8\u6001\u53c2\u6570<\/td>\n<td align=\"left\">\/user\/&lt;int:user_id&gt;<\/td>\n<td align=\"left\">\u652f\u6301 int, float, path, uuid<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">HTTP \u65b9\u6cd5<\/td>\n<td align=\"left\">methods&#061;[&#039;GET&#039;, &#039;POST&#039;]<\/td>\n<td align=\"left\">\u9ed8\u8ba4\u4ec5 GET<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">URL \u6784\u5efa<\/td>\n<td align=\"left\">url_for(&#039;index&#039;, _external&#061;True)<\/td>\n<td align=\"left\">\u907f\u514d\u786c\u7f16\u7801&#xff0c;\u652f\u6301\u53cd\u5411\u89e3\u6790<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u9759\u6001\u6587\u4ef6<\/td>\n<td align=\"left\">url_for(&#039;static&#039;, filename&#061;&#039;css\/style.css&#039;)<\/td>\n<td align=\"left\">\u81ea\u52a8\u6620\u5c04 \/static \u76ee\u5f55<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>2.2 \u8bf7\u6c42\u6570\u636e\u63d0\u53d6<\/h4>\n<p><span class=\"token keyword\">from<\/span> flask <span class=\"token keyword\">import<\/span> request<\/p>\n<p><span class=\"token comment\"># 1. \u67e5\u8be2\u53c2\u6570 ?key&#061;value<\/span><br \/>\nval <span class=\"token operator\">&#061;<\/span> request<span class=\"token punctuation\">.<\/span>args<span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;key&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;default&#039;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># 2. \u8868\u5355\u6570\u636e (application\/x-www-form-urlencoded)<\/span><br \/>\nval <span class=\"token operator\">&#061;<\/span> request<span class=\"token punctuation\">.<\/span>form<span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;username&#039;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># 3. JSON \u6570\u636e (application\/json)<\/span><br \/>\ndata <span class=\"token operator\">&#061;<\/span> request<span class=\"token punctuation\">.<\/span>get_json<span class=\"token punctuation\">(<\/span>silent<span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">True<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># 4. \u6587\u4ef6\u4e0a\u4f20<\/span><br \/>\n<span class=\"token builtin\">file<\/span> <span class=\"token operator\">&#061;<\/span> request<span class=\"token punctuation\">.<\/span>files<span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;avatar&#039;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token builtin\">file<\/span><span class=\"token punctuation\">.<\/span>save<span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f&#034;uploads\/<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span><span class=\"token builtin\">file<\/span><span class=\"token punctuation\">.<\/span>filename<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><\/p>\n<hr \/>\n<h3>3. \u6a21\u677f\u5f15\u64ce (Jinja2)<\/h3>\n<h4>3.1 \u6838\u5fc3\u8bed\u6cd5<\/h4>\n<ul>\n<li>\u53d8\u91cf\u8f93\u51fa&#xff1a;{{ user.name }}<\/li>\n<li>\u63a7\u5236\u6d41&#xff1a;{% if user.is_admin %} &#8230; {% endif %}<\/li>\n<li>\u5faa\u73af&#xff1a;{% for item in items %} &#8230; {% endfor %}<\/li>\n<li>\u7ee7\u627f&#xff1a;{% extends &#034;base.html&#034; %} &#043; {% block content %}{% endblock %}<\/li>\n<\/ul>\n<h4>3.2 \u5b89\u5168\u4e0e\u8fc7\u6ee4\u5668<\/h4>\n<ul>\n<li>\u81ea\u52a8\u8f6c\u4e49&#xff1a;Flask \u9ed8\u8ba4\u5f00\u542f&#xff0c;\u9632 XSS\u3002<\/li>\n<li>\u53d6\u6d88\u8f6c\u4e49&#xff1a;{{ html_content | safe }}&#xff08;\u4ec5\u7528\u4e8e\u53ef\u4fe1\u5185\u5bb9&#xff09;<\/li>\n<li>\u5e38\u7528\u8fc7\u6ee4\u5668&#xff1a;{{ date | datetimeformat }}, {{ text | truncate(50) }}<\/li>\n<\/ul>\n<hr \/>\n<h3>4. \u6570\u636e\u5e93\u4e0e ORM (Flask-SQLAlchemy)<\/h3>\n<h4>4.1 \u6a21\u578b\u5b9a\u4e49<\/h4>\n<p><span class=\"token keyword\">from<\/span> flask_sqlalchemy <span class=\"token keyword\">import<\/span> SQLAlchemy<\/p>\n<p>db <span class=\"token operator\">&#061;<\/span> SQLAlchemy<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">User<\/span><span class=\"token punctuation\">(<\/span>db<span class=\"token punctuation\">.<\/span>Model<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token builtin\">id<\/span> <span class=\"token operator\">&#061;<\/span> db<span class=\"token punctuation\">.<\/span>Column<span class=\"token punctuation\">(<\/span>db<span class=\"token punctuation\">.<\/span>Integer<span class=\"token punctuation\">,<\/span> primary_key<span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">True<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    username <span class=\"token operator\">&#061;<\/span> db<span class=\"token punctuation\">.<\/span>Column<span class=\"token punctuation\">(<\/span>db<span class=\"token punctuation\">.<\/span>String<span class=\"token punctuation\">(<\/span><span class=\"token number\">80<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> unique<span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">True<\/span><span class=\"token punctuation\">,<\/span> nullable<span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">False<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    posts <span class=\"token operator\">&#061;<\/span> db<span class=\"token punctuation\">.<\/span>relationship<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;Post&#039;<\/span><span class=\"token punctuation\">,<\/span> backref<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;author&#039;<\/span><span class=\"token punctuation\">,<\/span> lazy<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;dynamic&#039;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<h4>4.2 \u5e38\u7528\u64cd\u4f5c<\/h4>\n<p><span class=\"token comment\"># \u589e<\/span><br \/>\ndb<span class=\"token punctuation\">.<\/span>session<span class=\"token punctuation\">.<\/span>add<span class=\"token punctuation\">(<\/span>user<span class=\"token punctuation\">)<\/span><br \/>\ndb<span class=\"token punctuation\">.<\/span>session<span class=\"token punctuation\">.<\/span>commit<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u67e5<\/span><br \/>\nuser <span class=\"token operator\">&#061;<\/span> User<span class=\"token punctuation\">.<\/span>query<span class=\"token punctuation\">.<\/span>filter_by<span class=\"token punctuation\">(<\/span>username<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;admin&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span>first<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\nusers <span class=\"token operator\">&#061;<\/span> User<span class=\"token punctuation\">.<\/span>query<span class=\"token punctuation\">.<\/span><span class=\"token builtin\">filter<\/span><span class=\"token punctuation\">(<\/span>User<span class=\"token punctuation\">.<\/span><span class=\"token builtin\">id<\/span> <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">10<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token builtin\">all<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u6539<\/span><br \/>\nuser<span class=\"token punctuation\">.<\/span>username <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;new_name&#039;<\/span><br \/>\ndb<span class=\"token punctuation\">.<\/span>session<span class=\"token punctuation\">.<\/span>commit<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u5220<\/span><br \/>\ndb<span class=\"token punctuation\">.<\/span>session<span class=\"token punctuation\">.<\/span>delete<span class=\"token punctuation\">(<\/span>user<span class=\"token punctuation\">)<\/span><br \/>\ndb<span class=\"token punctuation\">.<\/span>session<span class=\"token punctuation\">.<\/span>commit<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<hr \/>\n<h3>5. \u6838\u5fc3\u6269\u5c55\u751f\u6001<\/h3>\n<table>\n<tr>\u6269\u5c55\u540d\u7528\u9014\u5907\u6ce8<\/tr>\n<tbody>\n<tr>\n<td align=\"left\">Flask-SQLAlchemy<\/td>\n<td align=\"left\">\u6570\u636e\u5e93 ORM<\/td>\n<td align=\"left\">\u7b80\u5316\u6570\u636e\u5e93\u64cd\u4f5c<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">Flask-Migrate<\/td>\n<td align=\"left\">\u6570\u636e\u5e93\u8fc1\u79fb<\/td>\n<td align=\"left\">\u57fa\u4e8e Alembic&#xff0c;\u7ba1\u7406\u8868\u7ed3\u6784\u53d8\u66f4<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">Flask-Login<\/td>\n<td align=\"left\">\u7528\u6237\u8ba4\u8bc1<\/td>\n<td align=\"left\">\u7ba1\u7406 current_user, \u767b\u5f55\/\u767b\u51fa<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">Flask-WTF<\/td>\n<td align=\"left\">\u8868\u5355\u5904\u7406<\/td>\n<td align=\"left\">\u8868\u5355\u9a8c\u8bc1 &#043; CSRF \u9632\u62a4<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">Flask-RESTful<\/td>\n<td align=\"left\">API \u5f00\u53d1<\/td>\n<td align=\"left\">\u8d44\u6e90\u7c7b\u89c6\u56fe&#xff0c;\u5feb\u901f\u6784\u5efa REST API<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">Flask-Caching<\/td>\n<td align=\"left\">\u7f13\u5b58<\/td>\n<td align=\"left\">\u652f\u6301 Redis\/Memcached<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>6. \u9879\u76ee\u67b6\u6784&#xff1a;\u84dd\u56fe (Blueprint)<\/h3>\n<p>\u89e3\u51b3\u5927\u578b\u9879\u76ee\u4ee3\u7801\u8026\u5408\u95ee\u9898&#xff0c;\u5b9e\u73b0\u6a21\u5757\u5316\u3002<\/p>\n<p><span class=\"token comment\"># app\/auth\/views.py<\/span><br \/>\n<span class=\"token keyword\">from<\/span> flask <span class=\"token keyword\">import<\/span> Blueprint<\/p>\n<p>auth_bp <span class=\"token operator\">&#061;<\/span> Blueprint<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;auth&#039;<\/span><span class=\"token punctuation\">,<\/span> __name__<span class=\"token punctuation\">,<\/span> url_prefix<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;\/auth&#039;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token decorator annotation punctuation\">&#064;auth_bp<span class=\"token punctuation\">.<\/span>route<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\/login&#039;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">def<\/span> <span class=\"token function\">login<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;Login Page&#034;<\/span><\/p>\n<p><span class=\"token comment\"># app\/__init__.py<\/span><br \/>\n<span class=\"token keyword\">from<\/span> app<span class=\"token punctuation\">.<\/span>auth<span class=\"token punctuation\">.<\/span>views <span class=\"token keyword\">import<\/span> auth_bp<\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">create_app<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    app <span class=\"token operator\">&#061;<\/span> Flask<span class=\"token punctuation\">(<\/span>__name__<span class=\"token punctuation\">)<\/span><br \/>\n    app<span class=\"token punctuation\">.<\/span>register_blueprint<span class=\"token punctuation\">(<\/span>auth_bp<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> app<\/p>\n<hr \/>\n<h3>7. \u5b89\u5168\u4e0e\u751f\u4ea7\u90e8\u7f72<\/h3>\n<h4>7.1 \u5b89\u5168\u6e05\u5355<\/h4>\n<li>SECRET_KEY&#xff1a;\u5fc5\u987b\u8bbe\u7f6e\u5f3a\u968f\u673a\u5bc6\u94a5&#xff0c;\u7528\u4e8e Session \u7b7e\u540d\u3002<\/li>\n<li>CSRF&#xff1a;\u6240\u6709\u8868\u5355\u5fc5\u987b\u5305\u542b CSRF Token (Flask-WTF)\u3002<\/li>\n<li>\u5bc6\u7801\u5b58\u50a8&#xff1a;\u7981\u6b62\u660e\u6587&#xff0c;\u4f7f\u7528 werkzeug.security.generate_password_hash\u3002<\/li>\n<li>\u8f93\u5165\u9a8c\u8bc1&#xff1a;\u6c38\u8fdc\u4e0d\u8981\u4fe1\u4efb\u5ba2\u6237\u7aef\u6570\u636e&#xff0c;\u540e\u7aef\u5fc5\u987b\u6821\u9a8c\u3002<\/li>\n<h4>7.2 \u751f\u4ea7\u90e8\u7f72\u65b9\u6848<\/h4>\n<p>\u7981\u6b62&#xff1a;app.run()&#xff08;Werkzeug \u5f00\u53d1\u670d\u52a1\u5668\u6027\u80fd\u5dee\u4e14\u4e0d\u7a33\u5b9a&#xff09;<\/p>\n<p>\u63a8\u8350\u6808&#xff1a;<\/p>\n<li>\n<p>WSGI \u670d\u52a1\u5668&#xff1a;Gunicorn (Linux) \u6216 Waitress (Windows)<\/p>\n<p>gunicorn <span class=\"token parameter variable\">-w<\/span> <span class=\"token number\">4<\/span> <span class=\"token parameter variable\">-b<\/span> <span class=\"token number\">0.0<\/span>.0.0:5000 <span class=\"token string\">&#034;app:create_app()&#034;<\/span><\/p>\n<\/li>\n<li>\n<p>\u53cd\u5411\u4ee3\u7406&#xff1a;Nginx<\/p>\n<ul>\n<li>\u5904\u7406\u9759\u6001\u6587\u4ef6 (CSS\/JS\/Images)<\/li>\n<li>SSL \u7ec8\u6b62 (HTTPS)<\/li>\n<li>\u8d1f\u8f7d\u5747\u8861<\/li>\n<li>\u8f6c\u53d1\u8bf7\u6c42\u5230 Gunicorn<\/li>\n<\/ul>\n<\/li>\n<hr \/>\n<h3>8. \u5b9e\u6218\u5b66\u4e60\u8def\u5f84<\/h3>\n<li>\u5165\u95e8&#xff1a;\u4e2a\u4eba\u535a\u5ba2&#xff08;\u8def\u7531\u3001\u6a21\u677f\u3001SQLite\u3001CRUD&#xff09;<\/li>\n<li>\u8fdb\u9636&#xff1a;\u7528\u6237\u7cfb\u7edf&#xff08;\u6ce8\u518c\/\u767b\u5f55\/\u6743\u9650\/\u90ae\u7bb1\u9a8c\u8bc1\/\u5934\u50cf\u4e0a\u4f20&#xff09;<\/li>\n<li>\u9ad8\u9636&#xff1a;RESTful API&#xff08;JSON \u54cd\u5e94\u3001Swagger \u6587\u6863\u3001Redis \u7f13\u5b58\u3001Celery \u5f02\u6b65\u4efb\u52a1&#xff09;<\/li>\n<li>\u67b6\u6784&#xff1a;\u5fae\u670d\u52a1\u62c6\u5206\u3001Docker \u5bb9\u5668\u5316\u90e8\u7f72\u3001CI\/CD \u6d41\u6c34\u7ebf<\/li>\n<hr \/>\n","protected":false},"excerpt":{"rendered":"<p>1. \u5feb\u901f\u542f\u52a8\u4e0e\u73af\u5883\u914d\u7f6e<br \/>\n1.1 \u865a\u62df\u73af\u5883&#xff08;\u5fc5\u9009&#xff09;<br \/>\n# \u521b\u5efa<br \/>\npython -m venv venv# \u6fc0\u6d3b (Windows)<br \/>\nvenv\\\\Scripts\\\\activate<br \/>\n# \u6fc0\u6d3b (Mac\/Linux)<br \/>\nsource venv\/bin\/activate# \u5b89\u88c5<br \/>\npip install flask1.2 \u6700\u5c0f\u5e94\u7528\u7ed3\u6784<br \/>\nfrom flask import Flaskapp  Flask(__name__)app.route(\/)<br \/>\ndef index<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[153,81,292],"topic":[],"class_list":["post-92812","post","type-post","status-publish","format-standard","hentry","category-server","tag-flask","tag-python","tag-292"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Flask \u6838\u5fc3\u901f\u67e5\u4e0e\u5b9e\u6218\u624b\u518c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/92812.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Flask \u6838\u5fc3\u901f\u67e5\u4e0e\u5b9e\u6218\u624b\u518c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"1. \u5feb\u901f\u542f\u52a8\u4e0e\u73af\u5883\u914d\u7f6e 1.1 \u865a\u62df\u73af\u5883&#xff08;\u5fc5\u9009&#xff09; # \u521b\u5efa python -m venv venv# \u6fc0\u6d3b (Windows) venv\\Scripts\\activate # \u6fc0\u6d3b (Mac\/Linux) source venv\/bin\/activate# \u5b89\u88c5 pip install flask1.2 \u6700\u5c0f\u5e94\u7528\u7ed3\u6784 from flask import Flaskapp Flask(__name__)app.route(\/) def index\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/92812.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-11T03:16:57+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/92812.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/92812.html\",\"name\":\"Flask \u6838\u5fc3\u901f\u67e5\u4e0e\u5b9e\u6218\u624b\u518c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-11T03:16:57+00:00\",\"dateModified\":\"2026-08-11T03:16:57+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/92812.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/92812.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/92812.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Flask \u6838\u5fc3\u901f\u67e5\u4e0e\u5b9e\u6218\u624b\u518c\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Flask \u6838\u5fc3\u901f\u67e5\u4e0e\u5b9e\u6218\u624b\u518c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/92812.html","og_locale":"zh_CN","og_type":"article","og_title":"Flask \u6838\u5fc3\u901f\u67e5\u4e0e\u5b9e\u6218\u624b\u518c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"1. \u5feb\u901f\u542f\u52a8\u4e0e\u73af\u5883\u914d\u7f6e 1.1 \u865a\u62df\u73af\u5883&#xff08;\u5fc5\u9009&#xff09; # \u521b\u5efa python -m venv venv# \u6fc0\u6d3b (Windows) venv\\Scripts\\activate # \u6fc0\u6d3b (Mac\/Linux) source venv\/bin\/activate# \u5b89\u88c5 pip install flask1.2 \u6700\u5c0f\u5e94\u7528\u7ed3\u6784 from flask import Flaskapp Flask(__name__)app.route(\/) def index","og_url":"https:\/\/www.wsisp.com\/helps\/92812.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-11T03:16:57+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/92812.html","url":"https:\/\/www.wsisp.com\/helps\/92812.html","name":"Flask \u6838\u5fc3\u901f\u67e5\u4e0e\u5b9e\u6218\u624b\u518c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-11T03:16:57+00:00","dateModified":"2026-08-11T03:16:57+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/92812.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/92812.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/92812.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Flask \u6838\u5fc3\u901f\u67e5\u4e0e\u5b9e\u6218\u624b\u518c"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/92812","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=92812"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/92812\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=92812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=92812"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=92812"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=92812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}