{"id":85679,"date":"2026-07-27T21:09:07","date_gmt":"2026-07-27T13:09:07","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/85679.html"},"modified":"2026-07-27T21:09:07","modified_gmt":"2026-07-27T13:09:07","slug":"%e5%9f%ba%e4%ba%8e-fastapi-tortoise-orm-%e7%9a%84%e4%bc%81%e4%b8%9a%e7%ab%af%e6%b3%a8%e5%86%8c%e8%ae%a4%e8%af%81%e6%a8%a1%e5%9d%97%e8%ae%be%e8%ae%a1%e4%b8%8e%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/85679.html","title":{"rendered":"\u57fa\u4e8e FastAPI + Tortoise ORM \u7684\u4f01\u4e1a\u7aef\u6ce8\u518c\u8ba4\u8bc1\u6a21\u5757\u8bbe\u8ba1\u4e0e\u5b9e\u73b0"},"content":{"rendered":"<h2><\/h2>\n<p>\u5173\u952e\u8bcd&#xff1a;FastAPI\u3001Tortoise ORM\u3001\u4f01\u4e1a\u8ba4\u8bc1\u3001\u591a\u8868\u4e8b\u52a1\u3001\u963f\u91cc\u4e91 OSS\u3001Pydantic v2<\/p>\n<h3>\u524d\u8a00<\/h3>\n<p>\u5728\u62db\u8058\u7c7b\u5e73\u53f0&#xff08;\u5982 BOSS \u76f4\u8058\u7c7b\u4ea7\u54c1&#xff09;\u4e2d&#xff0c;\u4f01\u4e1a\u7aef\u6ce8\u518c\u548c\u666e\u901a\u7528\u6237\u6ce8\u518c\u6709\u672c\u8d28\u533a\u522b&#xff1a;\u4f01\u4e1a\u4e0d\u662f&#034;\u586b\u4e2a\u8d26\u53f7\u5bc6\u7801\u5c31\u80fd\u7528&#034;&#xff0c;\u800c\u662f\u5fc5\u987b\u63d0\u4ea4\u8425\u4e1a\u6267\u7167\u3001\u6cd5\u4eba\u8eab\u4efd\u8bc1\u3001\u7edf\u4e00\u793e\u4f1a\u4fe1\u7528\u4ee3\u7801\u7b49\u8d44\u8d28\u6750\u6599&#xff0c;\u7ecf\u8fc7\u5e73\u53f0\u5ba1\u6838\u540e\u624d\u80fd\u53d1\u5e03\u804c\u4f4d\u3002\u672c\u6587\u590d\u76d8\u6211\u6700\u8fd1\u843d\u5730\u7684\u4e00\u4e2a\u4f01\u4e1a\u7aef\u6ce8\u518c\/\u8ba4\u8bc1\u540e\u7aef\u6a21\u5757&#xff0c;\u4ece\u4e1a\u52a1\u573a\u666f\u3001\u6570\u636e\u5e93\u8bbe\u8ba1\u5230\u5f00\u53d1\u6d41\u7a0b\u5b8c\u6574\u62c6\u89e3&#xff0c;\u5e76\u603b\u7ed3\u51e0\u4e2a\u5b9e\u6218\u4e2d\u8e29\u5230\u7684\u5751\u3002<\/p>\n<p>\u6280\u672f\u6808&#xff1a;Python 3.11 &#043; FastAPI &#043; Tortoise ORM&#xff08;\u5f02\u6b65&#xff09; &#043; \u963f\u91cc\u4e91 OSS &#043; SQLite\/MySQL\u3002<\/p>\n<hr \/>\n<h3>\u4e00\u3001\u4e1a\u52a1\u573a\u666f\u5206\u6790<\/h3>\n<h4>1.1 \u4e1a\u52a1\u5b9a\u4f4d<\/h4>\n<p>\u4f01\u4e1a\u7aef\u7528\u6237\u7684\u6838\u5fc3\u8bc9\u6c42\u662f&#034;\u5c3d\u5feb\u901a\u8fc7\u5ba1\u6838\u3001\u5f00\u59cb\u62db\u4eba&#034;&#xff0c;\u800c\u5e73\u53f0\u7684\u6838\u5fc3\u8bc9\u6c42\u662f&#034;\u786e\u4fdd\u5165\u9a7b\u4f01\u4e1a\u771f\u5b9e\u5408\u6cd5\u3001\u53ef\u63a7\u53ef\u5c01\u7981&#034;\u3002\u4e24\u8005\u5929\u7136\u5b58\u5728\u5f20\u529b&#xff0c;\u6ce8\u518c\u6a21\u5757\u5c31\u8981\u5728\u8fd9\u4e4b\u95f4\u505a\u5e73\u8861&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5bf9\u4f01\u4e1a&#xff1a;\u8868\u5355\u4e00\u6b21\u586b\u5b8c\u3001\u6750\u6599\u53ef\u4e0a\u4f20\u3001\u63d0\u4ea4\u540e\u8fdb\u5165&#034;\u5f85\u5ba1\u6838&#034;\u72b6\u6001&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u5bf9\u5e73\u53f0&#xff1a;\u591a\u7ef4\u5ea6\u8d44\u8d28\u7559\u5b58&#xff08;\u8425\u4e1a\u6267\u7167\u3001\u8eab\u4efd\u8bc1\u3001\u4fe1\u7528\u4ee3\u7801&#xff09;\u3001\u72b6\u6001\u673a\u7ba1\u63a7&#xff08;\u5f85\u5ba1\u6838 \u2192 \u6b63\u5e38 \/ \u5c01\u7981&#xff09;\u3001\u98ce\u63a7\u5b57\u6bb5&#xff08;\u98ce\u9669\u7b49\u7ea7\u3001\u9ed1\u540d\u5355\u3001\u6295\u8bc9\u6b21\u6570&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>1.2 \u6ce8\u518c \u2260 \u8ba4\u8bc1&#xff0c;\u4f46\u672c\u6b21\u5408\u5e76\u5904\u7406<\/h4>\n<p>\u7406\u60f3\u67b6\u6784\u91cc&#034;\u8d26\u53f7\u6ce8\u518c&#034;\u548c&#034;\u4f01\u4e1a\u8ba4\u8bc1&#034;\u662f\u4e24\u4ef6\u4e8b\u3002\u4f46\u5728 MVP \u9636\u6bb5&#xff0c;\u6211\u4eec\u628a\u4f01\u4e1a\u57fa\u7840\u4fe1\u606f &#043; \u8d44\u8d28\u6750\u6599 &#043; \u8d26\u53f7\u521d\u59cb\u5316\u5408\u5e76\u5230\u4e00\u6b21\u63d0\u4ea4\u91cc&#xff0c;\u7531\u540e\u7aef\u5728\u4e00\u4e2a\u6570\u636e\u5e93\u4e8b\u52a1\u4e2d\u843d\u4e09\u5f20\u8868&#xff0c;\u6ce8\u518c\u6210\u529f\u5373\u8fdb\u5165 PENDING_AUDIT&#xff08;\u5f85\u5ba1\u6838&#xff09; \u72b6\u6001&#xff0c;\u5ba1\u6838\u901a\u8fc7\u540e\u624d\u8f6c\u4e3a NORMAL&#xff08;\u6b63\u5e38&#xff09;\u3002<\/p>\n<h4>1.3 \u6838\u5fc3\u6d41\u7a0b<\/h4>\n<p>\u00a0\u4f01\u4e1a\u586b\u5199\u8868\u5355 &#043; \u4e0a\u4f20\u4e09\u8bc1<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  \u2502<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  \u25bc<br \/>\n\u00a0POST \/enterprise\/save  (multipart\/form-data)<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  \u2502<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  \u251c\u2500 1. \u521b\u5efa\u4f01\u4e1a\u4e3b\u8868 t_enterprise&#xff08;\u72b6\u6001&#061;\u5f85\u5ba1\u6838, code&#061;uuid&#xff09;<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  \u251c\u2500 2. \u521b\u5efa\u4f01\u4e1a\u4fe1\u606f\u8868 t_enterprise_info&#xff08;\u57fa\u7840\u5de5\u5546\u4fe1\u606f&#xff09;<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  \u251c\u2500 3. \u4e09\u5f20\u56fe\u7247\u4e0a\u4f20\u963f\u91cc\u4e91 OSS \u2192 \u62ff\u5230\u8bbf\u95ee URL<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  \u2514\u2500 4. \u521b\u5efa\u8d44\u8d28\u6750\u6599\u8868 t_enterprise_qualification&#xff08;URL &#043; \u8054\u7cfb\u4eba &#043; \u673a\u6784\u4ee3\u7801&#xff09;<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  \u2502<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  \u25bc<br \/>\n\u00a0\u8fd4\u56de {code:1, message:&#034;\u4fdd\u5b58\u6210\u529f&#034;}&#xff0c;\u524d\u7aef\u8fdb\u5165&#034;\u5ba1\u6838\u4e2d&#034;\u9875 <\/p>\n<hr \/>\n<h3>\u4e8c\u3001\u6570\u636e\u5e93\u8bbe\u8ba1<\/h3>\n<h4>2.1 \u6574\u4f53\u601d\u8def&#xff1a;\u4e00\u4e3b\u4e24\u4ece&#xff0c;\u6309&#034;\u7a33\u5b9a\u6027&#034;\u5206\u8868<\/h4>\n<p>\u6211\u628a\u4f01\u4e1a\u6570\u636e\u6309\u53d8\u66f4\u9891\u7387\u548c\u7528\u9014\u62c6\u6210\u4e09\u5f20\u8868&#xff0c;\u800c\u4e0d\u662f\u4e00\u80a1\u8111\u585e\u8fdb\u4e00\u5f20\u5927\u8868&#xff1a;<\/p>\n<table>\n<tr>\u8868\u540d\u4f5c\u7528\u53d8\u66f4\u9891\u7387\u5173\u952e\u5b57\u6bb5<\/tr>\n<tbody>\n<tr>\n<td>t_enterprise<\/td>\n<td>\u4f01\u4e1a\u4e3b\u8868&#xff08;\u8d26\u53f7\u7ef4\u5ea6&#xff09;<\/td>\n<td>\u6781\u4f4e<\/td>\n<td>\u72b6\u6001\u3001\u8ba4\u8bc1\u7c7b\u578b\u3001\u98ce\u9669\u7b49\u7ea7\u3001\u9ed1\u540d\u5355<\/td>\n<\/tr>\n<tr>\n<td>t_enterprise_info<\/td>\n<td>\u4f01\u4e1a\u5de5\u5546\u4fe1\u606f\u8868<\/td>\n<td>\u4f4e<\/td>\n<td>\u4fe1\u7528\u4ee3\u7801\u3001\u6cd5\u4eba\u3001\u6ce8\u518c\u8d44\u672c\u3001\u884c\u4e1a\u3001\u89c4\u6a21<\/td>\n<\/tr>\n<tr>\n<td>t_enterprise_qualification<\/td>\n<td>\u8d44\u8d28\u6750\u6599\u8868<\/td>\n<td>\u6781\u4f4e<\/td>\n<td>\u4e09\u8bc1\u56fe\u7247 URL\u3001\u8054\u7cfb\u4eba\u3001\u673a\u6784\u4ee3\u7801<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u62c6\u8868\u7684\u597d\u5904&#xff1a;\u4e3b\u8868\u8d1f\u8d23&#034;\u8d26\u53f7\u751f\u547d\u5468\u671f\u4e0e\u98ce\u63a7&#034;&#xff0c;\u4fe1\u606f\u8868\u8d1f\u8d23&#034;\u5de5\u5546\u6863\u6848&#034;&#xff0c;\u8d44\u8d28\u8868\u8d1f\u8d23&#034;\u5ba1\u6838\u6750\u6599&#034;\u3002\u5ba1\u6838\u6d41\u3001\u98ce\u63a7\u6d41\u53ea\u78b0\u4e3b\u8868&#xff0c;\u4e0d\u4f1a\u548c\u6d77\u91cf\u5de5\u5546\u5b57\u6bb5\u8026\u5408\u3002<\/p>\n<p>\u8bbe\u8ba1\u53d6\u820d&#xff1a;\u4e09\u5f20\u8868\u4e4b\u95f4\u6211\u7528 enterprise_id&#xff08;\u666e\u901a Int \u5b57\u6bb5&#xff09;\u5173\u8054&#xff0c;\u800c\u975e\u6570\u636e\u5e93\u5916\u952e\u3002\u7406\u7531\u662f\u5ba1\u6838\u4e1a\u52a1\u91cc&#034;\u5148\u5efa\u4e3b\u8868\u62ff ID\u3001\u518d\u5efa\u5b50\u8868&#034;\u7684\u65f6\u5e8f\u6e05\u6670&#xff0c;\u4e14\u907f\u514d\u5916\u952e\u5e26\u6765\u7684\u7ea7\u8054\u9501\u548c\u95ee\u9898\u3002\u4ee3\u4ef7\u662f\u5931\u53bb\u6570\u636e\u5e93\u5c42\u7684\u5f15\u7528\u5b8c\u6574\u6027&#xff0c;\u9700\u5728\u5e94\u7528\u5c42\u4fdd\u8bc1 enterprise_id \u4e00\u5b9a\u5b58\u5728&#xff08;\u9760\u4e8b\u52a1\u515c\u5e95&#xff09;\u3002<\/p>\n<h4>2.2 \u4f01\u4e1a\u4e3b\u8868 t_enterprise<\/h4>\n<p>\u00a0class Enterprise(Model):<br \/>\n\u00a0 \u00a0 \u00a0id &#061; fields.IntField(pk&#061;True)<br \/>\n\u00a0 \u00a0 \u00a0enterprise_name &#061; fields.CharField(max_length&#061;255)<br \/>\n\u00a0 \u00a0 \u00a0enterprise_code &#061; fields.CharField(max_length&#061;100, unique&#061;True) \u00a0# uuid \u751f\u6210<br \/>\n\u00a0 \u00a0 \u00a0city &#061; fields.ForeignKeyField(&#034;models.City&#034;, null&#061;True, on_delete&#061;fields.RESTRICT)<br \/>\n\u00a0 \u00a0 \u00a0account_status &#061; fields.IntEnumField(enum_type&#061;AccountStatus) \u00a0 \u00a0 # 0\u6b63\u5e38\/1\u5f85\u5ba1\u6838\/2\u5c01\u7981<br \/>\n\u00a0 \u00a0 \u00a0create_time &#061; fields.DatetimeField(auto_now_add&#061;True)<br \/>\n\u00a0 \u00a0 \u00a0auth_time &#061; fields.DatetimeField(null&#061;True)<br \/>\n\u00a0 \u00a0 \u00a0auth_type &#061; fields.IntEnumField(null&#061;True, enum_type&#061;AuthType)<br \/>\n\u00a0 \u00a0 \u00a0risk_level &#061; fields.IntEnumField(null&#061;True, enum_type&#061;RiskLevel)<br \/>\n\u00a0 \u00a0 \u00a0blacklist_status &#061; fields.IntEnumField(enum_type&#061;BlackListStatus)<br \/>\n\u00a0 \u00a0 \u00a0complaint_count &#061; fields.IntField(default&#061;0)<br \/>\n\u00a0 \u00a0 \u00a0company_website &#061; fields.CharField(max_length&#061;512, null&#061;True)<br \/>\n\u00a0 \u00a0 \u00a0email &#061; fields.CharField(max_length&#061;128, null&#061;True)<br \/>\n\u00a0 \u00a0 \u00a0audit_type &#061; fields.IntEnumField(enum_type&#061;AuditType)<br \/>\n\u00a0 \u00a0 \u00a0submit_time &#061; fields.DatetimeField(null&#061;True) <\/p>\n<h4>2.3 \u4f01\u4e1a\u4fe1\u606f\u8868 t_enterprise_info<\/h4>\n<p>\u00a0class EnterpriseInfo(Model):<br \/>\n\u00a0 \u00a0 \u00a0id &#061; fields.IntField(pk&#061;True)<br \/>\n\u00a0 \u00a0 \u00a0enterprise_name &#061; fields.CharField(max_length&#061;255)<br \/>\n\u00a0 \u00a0 \u00a0unified_social_credit_code &#061; fields.CharField(max_length&#061;50, unique&#061;True) \u00a0# \u7edf\u4e00\u793e\u4f1a\u4fe1\u7528\u4ee3\u7801\u552f\u4e00<br \/>\n\u00a0 \u00a0 \u00a0legal_representative &#061; fields.CharField(max_length&#061;100)<br \/>\n\u00a0 \u00a0 \u00a0registered_capital &#061; fields.CharField(max_length&#061;100)<br \/>\n\u00a0 \u00a0 \u00a0establish_date &#061; fields.DateField(null&#061;True)<br \/>\n\u00a0 \u00a0 \u00a0register_status &#061; fields.IntEnumField(enum_type&#061;RegisterStatus) \u00a0 # \u5b58\u7eed\/\u5728\u4e1a\/\u5f00\u4e1a&#8230;<br \/>\n\u00a0 \u00a0 \u00a0industry &#061; fields.ForeignKeyField(&#034;models.IndustryPosition&#034;, on_delete&#061;fields.RESTRICT)<br \/>\n\u00a0 \u00a0 \u00a0company_scale &#061; fields.IntEnumField(enum_type&#061;CompanyScale)<br \/>\n\u00a0 \u00a0 \u00a0financing_stage &#061; fields.IntEnumField(enum_type&#061;FinancingStage, null&#061;True)<br \/>\n\u00a0 \u00a0 \u00a0headquarters_address &#061; fields.CharField(max_length&#061;512)<br \/>\n\u00a0 \u00a0 \u00a0business_scope &#061; fields.TextField()<br \/>\n\u00a0 \u00a0 \u00a0enterprise_id &#061; fields.IntField(null&#061;True) <\/p>\n<h4>2.4 \u8d44\u8d28\u6750\u6599\u8868 t_enterprise_qualification<\/h4>\n<p>\u00a0class EnterpriseQualification(Model):<br \/>\n\u00a0 \u00a0 \u00a0id &#061; fields.IntField(pk&#061;True)<br \/>\n\u00a0 \u00a0 \u00a0contact_name &#061; fields.CharField(max_length&#061;100)<br \/>\n\u00a0 \u00a0 \u00a0contact_phone &#061; fields.CharField(max_length&#061;32)<br \/>\n\u00a0 \u00a0 \u00a0contact_email &#061; fields.CharField(max_length&#061;128)<br \/>\n\u00a0 \u00a0 \u00a0business_license_url &#061; fields.CharField(max_length&#061;512, null&#061;True)<br \/>\n\u00a0 \u00a0 \u00a0legal_id_front_url &#061; fields.CharField(max_length&#061;512, null&#061;True)<br \/>\n\u00a0 \u00a0 \u00a0legal_id_back_url &#061; fields.CharField(max_length&#061;512, null&#061;True)<br \/>\n\u00a0 \u00a0 \u00a0org_code_cert &#061; fields.CharField(max_length&#061;256, null&#061;True)<br \/>\n\u00a0 \u00a0 \u00a0enterprise_id &#061; fields.IntField(null&#061;True) <\/p>\n<h4>2.5 \u679a\u4e3e\u7edf\u4e00\u7528 IntEnum<\/h4>\n<p>\u6240\u6709&#034;\u72b6\u6001\u7c7b&#034;\u5b57\u6bb5\u90fd\u7528 IntEnum \u800c\u975e\u5b57\u7b26\u4e32&#xff0c;\u5b58\u5e93\u662f int\u3001\u4ee3\u7801\u91cc\u662f\u8bed\u4e49\u5316\u679a\u4e3e&#xff0c;\u517c\u987e\u6027\u80fd\u548c\u53ef\u8bfb\u6027&#xff1a;<\/p>\n<p>\u00a0class AccountStatus(IntEnum):<br \/>\n\u00a0 \u00a0 \u00a0NORMAL &#061; 0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0# \u6b63\u5e38<br \/>\n\u00a0 \u00a0 \u00a0PENDING_AUDIT &#061; 1 \u00a0 # \u5f85\u5ba1\u6838<br \/>\n\u00a0 \u00a0 \u00a0BANNED &#061; 2 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0# \u5c01\u7981<br \/>\n\u00a0\u200b<br \/>\n\u00a0class RegisterStatus(IntEnum):<br \/>\n\u00a0 \u00a0 \u00a0CONTINUE &#061; 1 \u00a0 \u00a0 \u00a0 \u00a0# \u5b58\u7eed<br \/>\n\u00a0 \u00a0 \u00a0IN_BUSINESS &#061; 2 \u00a0 \u00a0 # \u5728\u4e1a<br \/>\n\u00a0 \u00a0 \u00a0OPEN &#061; 3 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0# \u5f00\u4e1a<br \/>\n\u00a0 \u00a0 \u00a0SUSPENDED &#061; 4 \u00a0 \u00a0 \u00a0 # \u505c\u4e1a<br \/>\n\u00a0 \u00a0 \u00a0LIQUIDATION &#061; 5 \u00a0 \u00a0 # \u6e05\u7b97<br \/>\n\u00a0 \u00a0 \u00a0REVOKED &#061; 6 \u00a0 \u00a0 \u00a0 \u00a0 # \u540a\u9500<br \/>\n\u00a0 \u00a0 \u00a0CANCELLED &#061; 7 \u00a0 \u00a0 \u00a0 # \u6ce8\u9500<br \/>\n\u00a0\u200b<br \/>\n\u00a0class CompanyScale(IntEnum):<br \/>\n\u00a0 \u00a0 \u00a0SCALE_0_20 &#061; 1<br \/>\n\u00a0 \u00a0 \u00a0SCALE_20_99 &#061; 2<br \/>\n\u00a0 \u00a0 \u00a0SCALE_100_499 &#061; 3<br \/>\n\u00a0 \u00a0 \u00a0SCALE_500_999 &#061; 4<br \/>\n\u00a0 \u00a0 \u00a0SCALE_1000_9999 &#061; 5<br \/>\n\u00a0 \u00a0 \u00a0SCALE_10000_PLUS &#061; 6 <\/p>\n<p>\u524d\u7aef\u4e0b\u62c9\u6846\u76f4\u63a5\u7ed1\u5b9a\u679a\u4e3e int \u503c\u5373\u53ef&#xff0c;\u907f\u514d\u4e86&#034;\u4e2d\u6587\u6587\u6848\u5165\u5e93&#034;\u5e26\u6765\u7684\u810f\u6570\u636e\u548c\u6392\u5e8f\u96be\u9898\u3002<\/p>\n<hr \/>\n<h3>\u4e09\u3001\u5f00\u53d1\u6d41\u7a0b&#xff08;\u5206\u5c42\u67b6\u6784&#xff09;<\/h3>\n<p>\u6a21\u5757\u91c7\u7528\u6e05\u6670\u7684\u56db\u5c42&#xff1a;Router&#xff08;\u8def\u7531&#xff09; \u2192 Dependency&#xff08;\u8868\u5355\u89e3\u6790&#xff09; \u2192 Schema&#xff08;\u6821\u9a8c&#xff09; \u2192 Service&#xff08;\u4e1a\u52a1&#xff09; \u2192 Model&#xff08;\u843d\u5e93&#xff09;\u3002<\/p>\n<h4>3.1 \u63a5\u53e3\u5c42&#xff1a;\u7eaf\u8def\u7531&#xff0c;\u4e0d\u542b\u903b\u8f91<\/h4>\n<p>\u00a0&#064;enterprise_router.post(&#034;\/save&#034;, summary&#061;&#034;\u4fdd\u5b58\u4f01\u4e1a\u4fe1\u606f&#034;)<br \/>\n\u00a0async def saveEnterpriseInfo(<br \/>\n\u00a0 \u00a0 \u00a0form: EnterpriseCreateRequest &#061; Depends(get_enterprise_form),<br \/>\n\u00a0 \u00a0 \u00a0business_license_file: UploadFile &#061; File(None, description&#061;&#034;\u8425\u4e1a\u6267\u7167&#034;),<br \/>\n\u00a0 \u00a0 \u00a0legal_id_front_file: UploadFile &#061; File(None, description&#061;&#034;\u6cd5\u4eba\u8eab\u4efd\u8bc1&#xff08;\u6b63\u9762&#xff09;&#034;),<br \/>\n\u00a0 \u00a0 \u00a0legal_id_back_file: UploadFile &#061; File(None, description&#061;&#034;\u6cd5\u4eba\u8eab\u4efd\u8bc1&#xff08;\u53cd\u9762&#xff09;&#034;),<br \/>\n\u00a0):<br \/>\n\u00a0 \u00a0 \u00a0from app.services.enterrise_service import EnterpriseService<br \/>\n\u00a0 \u00a0 \u00a0await EnterpriseService.saveEnterpriseInfo(<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0form, business_license_file, legal_id_front_file, legal_id_back_file<br \/>\n\u00a0 \u00a0  )<br \/>\n\u00a0 \u00a0 \u00a0return {&#034;code&#034;: 1, &#034;message&#034;: &#034;\u4fdd\u5b58\u6210\u529f&#034;} <\/p>\n<p>\u8981\u70b9&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u7528 multipart\/form-data \u540c\u65f6\u6536\u6587\u672c\u5b57\u6bb5 &#043; \u6587\u4ef6&#xff0c;\u524d\u7aef\u7528 FormData \u63d0\u4ea4&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u6587\u672c\u5b57\u6bb5\u4ea4\u7ed9 Depends(get_enterprise_form) \u89e3\u6790&#xff0c;\u6587\u4ef6\u7528 File(&#8230;) \u63a5\u6536&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u8fd4\u56de\u7edf\u4e00\u7ed3\u6784 {code, message}&#xff0c;\u4e0e\u524d\u7aef\u7ea6\u5b9a\u4e00\u81f4\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>3.2 \u4f9d\u8d56\u5c42&#xff1a;\u628a Form \u53c2\u6570\u6620\u5c04\u6210\u5f3a\u7c7b\u578b Schema<\/h4>\n<p>FastAPI \u7684 Form \u4f9d\u8d56\u628a\u6563\u843d\u7684\u8868\u5355\u5b57\u6bb5\u805a\u5408\u6210\u4e00\u4e2a Pydantic \u6a21\u578b&#xff0c;\u8def\u7531\u91cc\u76f4\u63a5\u62ff\u5230\u7c7b\u578b\u5b89\u5168\u7684 form \u5bf9\u8c61&#xff1a;<\/p>\n<p>\u00a0<br \/>\nasync def get_enterprise_form(<br \/>\n\u00a0 \u00a0 \u00a0enterprise_name&#061;Form(&#8230;, description&#061;&#034;\u4f01\u4e1a\u540d\u79f0&#034;),<br \/>\n\u00a0 \u00a0 \u00a0unified_social_credit_code&#061;Form(&#8230;, description&#061;&#034;\u7edf\u4e00\u793e\u4f1a\u4fe1\u7528\u4ee3\u7801&#034;),<br \/>\n\u00a0 \u00a0 \u00a0legal_representative&#061;Form(&#8230;, description&#061;&#034;\u6cd5\u4eba\u4ee3\u8868&#034;),<br \/>\n\u00a0 \u00a0 \u00a0registered_capital&#061;Form(&#8230;, description&#061;&#034;\u6ce8\u518c\u8d44\u672c&#034;),<br \/>\n\u00a0 \u00a0 \u00a0establish_date&#061;Form(None, description&#061;&#034;\u6210\u7acb\u65e5\u671f&#034;),<br \/>\n\u00a0 \u00a0 \u00a0register_status&#061;Form(&#8230;, description&#061;&#034;\u767b\u8bb0\u72b6\u6001&#034;),<br \/>\n\u00a0 \u00a0 \u00a0industry_id&#061;Form(&#8230;, description&#061;&#034;\u6240\u5c5e\u884c\u4e1a&#034;),<br \/>\n\u00a0 \u00a0 \u00a0company_scale&#061;Form(&#8230;, description&#061;&#034;\u516c\u53f8\u89c4\u6a21&#034;),<br \/>\n\u00a0 \u00a0 \u00a0financing_stage&#061;Form(None, description&#061;&#034;\u878d\u8d44\u9636\u6bb5(\u53ef\u4e3a\u7a7a)&#034;),<br \/>\n\u00a0 \u00a0 \u00a0headquarters_address&#061;Form(&#8230;, description&#061;&#034;\u603b\u90e8\u5730\u5740&#034;),<br \/>\n\u00a0 \u00a0 \u00a0business_scope&#061;Form(&#8230;, description&#061;&#034;\u7ecf\u8425\u8303\u56f4&#034;),<br \/>\n\u00a0 \u00a0 \u00a0contact_name&#061;Form(&#8230;, description&#061;&#034;\u8054\u7cfb\u4eba\u59d3\u540d&#034;),<br \/>\n\u00a0 \u00a0 \u00a0contact_phone&#061;Form(&#8230;, description&#061;&#034;\u8054\u7cfb\u7535\u8bdd&#034;),<br \/>\n\u00a0 \u00a0 \u00a0contact_email&#061;Form(&#8230;, description&#061;&#034;\u8054\u7cfb\u90ae\u7bb1&#034;),<br \/>\n\u00a0 \u00a0 \u00a0org_code_cert&#061;Form(None, description&#061;&#034;\u7ec4\u7ec7\u673a\u6784\u4ee3\u7801\u8bc1&#034;),<br \/>\n\u00a0):<br \/>\n\u00a0 \u00a0 \u00a0return EnterpriseCreateRequest(<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0enterprise_name&#061;enterprise_name,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0unified_social_credit_code&#061;unified_social_credit_code,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0# &#8230; \u5176\u4f59\u5b57\u6bb5\u540c\u7406<br \/>\n\u00a0 \u00a0  ) <\/p>\n<h4>3.3 \u670d\u52a1\u5c42&#xff1a;\u4e8b\u52a1 &#043; OSS&#xff0c;\u4fdd\u8bc1&#034;\u8981\u4e48\u5168\u6210\u3001\u8981\u4e48\u5168\u8d25&#034;<\/h4>\n<p>\u8fd9\u662f\u6a21\u5757\u7684\u6838\u5fc3\u3002\u4e00\u6b21\u63d0\u4ea4\u8981\u5199\u4e09\u5f20\u8868 &#043; \u4f20\u4e09\u5f20\u56fe&#xff0c;\u5fc5\u987b\u539f\u5b50\u5316&#xff1a;<\/p>\n<p>\u00a0<br \/>\n&#064;staticmethod<br \/>\n\u00a0async def saveEnterpriseInfo(form, business_license_file,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 legal_id_front_file, legal_id_back_file):<br \/>\n\u00a0 \u00a0 \u00a0async with in_transaction() as conn:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0# 1. \u4e3b\u8868&#xff08;\u72b6\u6001\u76f4\u63a5\u7f6e\u4e3a\u5f85\u5ba1\u6838&#xff09;<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0enterprise &#061; await Enterprise.create(<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0enterprise_name&#061;form.enterprise_name,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0enterprise_code&#061;str(uuid.uuid4()),<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0account_status&#061;AccountStatus.PENDING_AUDIT,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0blacklist_status&#061;BlackListStatus.NOT_BANNED,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0audit_type&#061;AuditType.NEW_ENTERPRISE_AUTH,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0submit_time&#061;now(),<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  )<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0# 2. \u4fe1\u606f\u8868&#xff08;\u62ff\u5230\u4e3b\u8868 id \u56de\u586b&#xff09;<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0await EnterpriseInfo.create(<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0enterprise_name&#061;form.enterprise_name,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0unified_social_credit_code&#061;form.unified_social_credit_code,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0# &#8230; \u5176\u4f59\u5b57\u6bb5<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0enterprise_id&#061;enterprise.id<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  )<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0# 3. \u4e09\u5f20\u56fe\u4e0a\u4f20 OSS<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0oss &#061; AliyunOSSTool()<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0is_success, success_res &#061; oss.upload_single_file(<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0await business_license_file.read(),<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0business_license_file.filename, oss_path&#061;&#034;enterprise\/&#034;)<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0if not is_success:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0raise Exception(&#034;\u4e0a\u4f20\u8425\u4e1a\u6267\u7167\u56fe\u7247\u5931\u8d25&#034;)<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0# &#8230; \u8eab\u4efd\u8bc1\u6b63\u53cd\u9762\u540c\u7406<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0# 4. \u8d44\u8d28\u8868&#xff08;\u5199\u5165 OSS \u8fd4\u56de\u7684\u8bbf\u95ee URL&#xff09;<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0await EnterpriseQualification.create(<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0contact_name&#061;form.contact_name,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0contact_phone&#061;form.contact_phone,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0contact_email&#061;form.contact_email,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0org_code_cert&#061;form.org_code_cert,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0enterprise_id&#061;enterprise.id,<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0business_license_url&#061;success_res[&#034;access_url&#034;],<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0legal_id_front_url&#061;success_res2[&#034;access_url&#034;],<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0legal_id_back_url&#061;success_res3[&#034;access_url&#034;],<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0  ) <\/p>\n<p>\u5173\u952e\u70b9&#xff1a;\u6574\u6bb5\u5305\u5728 async with in_transaction() \u91cc\u3002\u53ea\u8981\u4efb\u4f55\u4e00\u6b65&#xff08;\u5c24\u5176\u662f OSS \u4e0a\u4f20&#xff09;\u629b\u5f02\u5e38&#xff0c;\u4e8b\u52a1\u6574\u4f53\u56de\u6eda&#xff0c;\u4e0d\u4f1a\u51fa\u73b0&#034;\u4e3b\u8868\u5efa\u4e86\u3001\u56fe\u7247\u6ca1\u4f20\u3001\u8d44\u8d28\u8868\u7f3a URL&#034;\u7684\u810f\u6570\u636e\u3002<\/p>\n<hr \/>\n<h3>\u56db\u3001\u8bbe\u8ba1\u4eae\u70b9\u4e0e\u8e29\u5751\u8bb0\u5f55<\/h3>\n<h4>4.1 \u4eae\u70b9&#xff1a;\u72b6\u6001\u673a\u4ece\u6ce8\u518c\u8d77\u5c31\u4ecb\u5165<\/h4>\n<p>account_status \u5728\u521b\u5efa\u4e3b\u8868\u65f6\u76f4\u63a5\u5199\u5165 PENDING_AUDIT&#xff0c;\u800c\u4e0d\u662f\u5148\u5efa\u4e2a&#034;\u6b63\u5e38&#034;\u8d26\u53f7\u518d\u6539\u3002\u8fd9\u610f\u5473\u7740\u4f01\u4e1a\u4ece\u8bde\u751f\u8d77\u5c31\u5904\u4e8e\u5e73\u53f0\u7ba1\u63a7\u4e4b\u4e0b&#xff0c;\u5ba1\u6838\u901a\u8fc7\u624d\u653e\u884c&#xff0c;\u5929\u7136\u9632\u4f4f&#034;\u672a\u5ba1\u5148\u53d1&#034;\u3002<\/p>\n<h4>4.2 \u4eae\u70b9&#xff1a;\u4f01\u4e1a Code \u7528 UUID&#xff0c;\u4e0d\u66b4\u9732\u81ea\u589e ID<\/h4>\n<p>\u5bf9\u5916\u66b4\u9732\u7684 enterprise_code \u662f uuid4()&#xff0c;\u907f\u514d\u7528\u81ea\u589e\u4e3b\u952e\u505a\u4e1a\u52a1\u6807\u8bc6\u5e26\u6765\u7684\u679a\u4e3e\u904d\u5386\u98ce\u9669\u3002<\/p>\n<h4>4.3 \u8e29\u5751&#xff1a;Pydantic v2 \u7684 str &#061; Field(None) \u662f\u4e2a\u9677\u9631<\/h4>\n<p>\u6211\u6700\u521d\u628a\u53ef\u9009\u6587\u672c\u5b57\u6bb5\u5199\u6210&#xff1a;<\/p>\n<p>org_code_cert: str &#061; Field(None, description&#061;&#034;\u7ec4\u7ec7\u673a\u6784\u4ee3\u7801\u8bc1&#034;)  # \u274c <\/p>\n<p>\u5728 Pydantic v2 \u91cc&#xff0c;\u7c7b\u578b\u662f str&#xff08;\u5fc5\u586b&#xff09;&#xff0c;\u5374\u7ed9\u4e86\u9ed8\u8ba4 None\u3002\u5f53\u524d\u7aef\u6ca1\u4f20\u8fd9\u4e2a key \u65f6&#xff0c;Pydantic \u7528\u9ed8\u8ba4\u503c None \u53bb\u6821\u9a8c str \u7c7b\u578b&#xff0c;\u76f4\u63a5\u62a5&#xff1a;<\/p>\n<p><span style=\"color:#ed7976\">org_code_cert<br \/>\n  Input should be a valid string [type&#061;string_type, input_value&#061;None]<\/span> <\/p>\n<p>\u6b63\u786e\u5199\u6cd5\u662f\u663e\u5f0f\u58f0\u660e\u53ef\u7a7a&#xff1a;<\/p>\n<p>from typing import Optional<br \/>\norg_code_cert: Optional[str] &#061; Field(None, description&#061;&#034;\u7ec4\u7ec7\u673a\u6784\u4ee3\u7801\u8bc1&#034;)  # \u2705 <\/p>\n<p>\u540c\u7406&#xff0c;establish_date: Optional[date]\u3001financing_stage: Optional[int] \u5982\u679c\u5141\u8bb8\u7559\u7a7a&#xff0c;\u4e5f\u90fd\u5fc5\u987b\u52a0 Optional&#xff0c;\u5426\u5219\u524d\u7aef\u7701\u7565\u8be5\u5b57\u6bb5\u5c31\u4f1a 422\u3002\u7ed3\u8bba&#xff1a;\u53ea\u8981\u5b57\u6bb5\u53ef\u80fd\u4e0d\u4f20&#xff0c;\u7c7b\u578b\u5c31\u5fc5\u987b\u662f Optional[X]\u3002<\/p>\n<h4>4.4 \u8e29\u5751&#xff1a;\u524d\u7aef&#034;\u6761\u4ef6 append&#034;\u4f1a\u8ba9\u53ef\u9009\u5b57\u6bb5\u53d8 None<\/h4>\n<p>\u524d\u7aef\u7528 if (value) formData.append(key, value) \u65f6&#xff0c;\u7a7a\u5b57\u7b26\u4e32 &#039;&#039; \u662f falsy&#xff0c;\u5b57\u6bb5\u4f1a\u88ab\u6574\u4e2a\u7701\u7565\u3002\u540e\u7aef\u6536\u4e0d\u5230 key \u2192 \u547d\u4e2d\u4e0a\u9762\u7684 None \u6821\u9a8c\u3002\u6539\u6210\u59cb\u7ec8 append \u7a7a\u4e32 formData.append(&#039;org_code_cert&#039;, value || &#039;&#039;) \u5373\u53ef\u89c4\u907f\u3002<\/p>\n<h4>4.5 \u6ce8\u610f&#xff1a;\u6587\u4ef6\u4e0a\u4f20\u5efa\u8bae\u9650\u5b9a\u7c7b\u578b\u4e0e\u5927\u5c0f<\/h4>\n<p>\u5f53\u524d business_license_file \u7b49\u662f File(None)&#xff0c;\u672a\u505a\u540e\u7f00\/\u5927\u5c0f\u6821\u9a8c\u3002\u751f\u4ea7\u73af\u5883\u5e94\u5728\u4f9d\u8d56\u5c42\u6216\u4e2d\u95f4\u4ef6\u52a0 content_type \u767d\u540d\u5355\u548c Content-Length \u4e0a\u9650&#xff0c;\u9632\u6b62\u8d85\u5927\u6587\u4ef6\u6216\u6076\u610f\u811a\u672c\u62d6\u57ae OSS\u3002<\/p>\n<hr \/>\n<h3>\u4e94\u3001\u603b\u7ed3<\/h3>\n<p>\u4f01\u4e1a\u7aef\u6ce8\u518c\u6a21\u5757\u770b\u4f3c\u53ea\u662f&#034;\u4e00\u4e2a\u8868\u5355\u63d0\u4ea4&#034;&#xff0c;\u80cc\u540e\u8981\u517c\u987e\u8d44\u8d28\u7559\u5b58\u3001\u98ce\u63a7\u72b6\u6001\u3001\u591a\u8868\u4e00\u81f4\u6027\u3001\u6587\u4ef6\u5b58\u50a8\u56db\u4ef6\u4e8b\u3002\u672c\u6587\u7684\u6838\u5fc3\u7ecf\u9a8c&#xff1a;<\/p>\n<li>\n<p>\u6309\u53d8\u66f4\u9891\u7387\u5206\u8868&#xff0c;\u4e3b\u8868\u7ba1\u751f\u547d\u5468\u671f\u3001\u5b50\u8868\u7ba1\u6863\u6848\u4e0e\u6750\u6599&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u72b6\u6001\u673a\u524d\u7f6e&#xff0c;\u6ce8\u518c\u5373\u8fdb\u5165\u5f85\u5ba1\u6838&#xff0c;\u5e73\u53f0\u59cb\u7ec8\u53ef\u63a7&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u591a\u5199\u64cd\u4f5c\u4e00\u5f8b\u5305\u4e8b\u52a1&#xff0c;\u5c24\u5176\u6d89\u53ca\u5916\u90e8\u5b58\u50a8&#xff08;OSS&#xff09;\u65f6&#xff0c;\u4e8b\u52a1\u56de\u6eda\u662f\u6570\u636e\u4e00\u81f4\u6027\u7684\u6700\u540e\u9632\u7ebf&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u679a\u4e3e\u7528 IntEnum\u3001\u53ef\u7a7a\u5b57\u6bb5\u5fc5\u987b Optional&#xff0c;\u8fd9\u662f FastAPI &#043; Pydantic v2 \u9879\u76ee\u91cc\u6700\u9ad8\u9891\u7684\u4e24\u4e2a\u5751\u3002<\/p>\n<\/li>\n<p>\u4e0b\u4e00\u7bc7\u53ef\u4ee5\u5c55\u5f00\u5199&#034;\u5ba1\u6838\u6d41&#034;\u2014\u2014\u7ba1\u7406\u5458\u5982\u4f55\u5728\u7ba1\u7406\u7aef\u67e5\u770b\u5f85\u5ba1\u4f01\u4e1a\u3001\u901a\u8fc7\/\u9a73\u56de\u5e76\u9a71\u52a8 account_status \u4e0e auth_time \u53d8\u66f4\u3002\u6b22\u8fce\u5728\u8bc4\u8bba\u533a\u4ea4\u6d41\u3002<\/p>\n<hr \/>\n","protected":false},"excerpt":{"rendered":"<p>\u5173\u952e\u8bcd&#xff1a;FastAPI\u3001Tortoise ORM\u3001\u4f01\u4e1a\u8ba4\u8bc1\u3001\u591a\u8868\u4e8b\u52a1\u3001\u963f\u91cc\u4e91 OSS\u3001Pydantic v2 \u524d\u8a00<br \/>\n\u5728\u62db\u8058\u7c7b\u5e73\u53f0&#xff08;\u5982 BOSS \u76f4\u8058\u7c7b\u4ea7\u54c1&#xff09;\u4e2d&#xff0c;\u4f01\u4e1a\u7aef\u6ce8\u518c\u548c\u666e\u901a\u7528\u6237\u6ce8\u518c\u6709\u672c\u8d28\u533a\u522b&#xff1a;\u4f01\u4e1a\u4e0d\u662f\\&#8221;\u586b\u4e2a\u8d26\u53f7\u5bc6\u7801\u5c31\u80fd\u7528\\&#8221;&#xff0c;\u800c\u662f\u5fc5\u987b\u63d0\u4ea4\u8425\u4e1a\u6267\u7167\u3001\u6cd5\u4eba\u8eab\u4efd\u8bc1\u3001\u7edf\u4e00\u793e\u4f1a\u4fe1\u7528\u4ee3\u7801\u7b49\u8d44\u8d28\u6750\u6599&#xff0c;\u7ecf\u8fc7\u5e73\u53f0\u5ba1\u6838\u540e\u624d\u80fd\u53d1\u5e03\u804c\u4f4d\u3002\u672c\u6587\u590d\u76d8\u6211\u6700\u8fd1\u843d\u5730\u7684\u4e00\u4e2a\u4f01\u4e1a\u7aef\u6ce8\u518c\/\u8ba4\u8bc1\u540e\u7aef\u6a21\u5757&amp;#xff0c<\/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":[72],"topic":[],"class_list":["post-85679","post","type-post","status-publish","format-standard","hentry","category-server","tag-fastapi"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u57fa\u4e8e FastAPI + Tortoise ORM \u7684\u4f01\u4e1a\u7aef\u6ce8\u518c\u8ba4\u8bc1\u6a21\u5757\u8bbe\u8ba1\u4e0e\u5b9e\u73b0 - \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\/85679.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u57fa\u4e8e FastAPI + Tortoise ORM \u7684\u4f01\u4e1a\u7aef\u6ce8\u518c\u8ba4\u8bc1\u6a21\u5757\u8bbe\u8ba1\u4e0e\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u5173\u952e\u8bcd&#xff1a;FastAPI\u3001Tortoise ORM\u3001\u4f01\u4e1a\u8ba4\u8bc1\u3001\u591a\u8868\u4e8b\u52a1\u3001\u963f\u91cc\u4e91 OSS\u3001Pydantic v2 \u524d\u8a00 \u5728\u62db\u8058\u7c7b\u5e73\u53f0&#xff08;\u5982 BOSS \u76f4\u8058\u7c7b\u4ea7\u54c1&#xff09;\u4e2d&#xff0c;\u4f01\u4e1a\u7aef\u6ce8\u518c\u548c\u666e\u901a\u7528\u6237\u6ce8\u518c\u6709\u672c\u8d28\u533a\u522b&#xff1a;\u4f01\u4e1a\u4e0d\u662f&quot;\u586b\u4e2a\u8d26\u53f7\u5bc6\u7801\u5c31\u80fd\u7528&quot;&#xff0c;\u800c\u662f\u5fc5\u987b\u63d0\u4ea4\u8425\u4e1a\u6267\u7167\u3001\u6cd5\u4eba\u8eab\u4efd\u8bc1\u3001\u7edf\u4e00\u793e\u4f1a\u4fe1\u7528\u4ee3\u7801\u7b49\u8d44\u8d28\u6750\u6599&#xff0c;\u7ecf\u8fc7\u5e73\u53f0\u5ba1\u6838\u540e\u624d\u80fd\u53d1\u5e03\u804c\u4f4d\u3002\u672c\u6587\u590d\u76d8\u6211\u6700\u8fd1\u843d\u5730\u7684\u4e00\u4e2a\u4f01\u4e1a\u7aef\u6ce8\u518c\/\u8ba4\u8bc1\u540e\u7aef\u6a21\u5757&amp;#xff0c\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/85679.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-07-27T13:09:07+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=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/85679.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/85679.html\",\"name\":\"\u57fa\u4e8e FastAPI + Tortoise ORM \u7684\u4f01\u4e1a\u7aef\u6ce8\u518c\u8ba4\u8bc1\u6a21\u5757\u8bbe\u8ba1\u4e0e\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-07-27T13:09:07+00:00\",\"dateModified\":\"2026-07-27T13:09:07+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/85679.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/85679.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/85679.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u57fa\u4e8e FastAPI + Tortoise ORM \u7684\u4f01\u4e1a\u7aef\u6ce8\u518c\u8ba4\u8bc1\u6a21\u5757\u8bbe\u8ba1\u4e0e\u5b9e\u73b0\"}]},{\"@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":"\u57fa\u4e8e FastAPI + Tortoise ORM \u7684\u4f01\u4e1a\u7aef\u6ce8\u518c\u8ba4\u8bc1\u6a21\u5757\u8bbe\u8ba1\u4e0e\u5b9e\u73b0 - \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\/85679.html","og_locale":"zh_CN","og_type":"article","og_title":"\u57fa\u4e8e FastAPI + Tortoise ORM \u7684\u4f01\u4e1a\u7aef\u6ce8\u518c\u8ba4\u8bc1\u6a21\u5757\u8bbe\u8ba1\u4e0e\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u5173\u952e\u8bcd&#xff1a;FastAPI\u3001Tortoise ORM\u3001\u4f01\u4e1a\u8ba4\u8bc1\u3001\u591a\u8868\u4e8b\u52a1\u3001\u963f\u91cc\u4e91 OSS\u3001Pydantic v2 \u524d\u8a00 \u5728\u62db\u8058\u7c7b\u5e73\u53f0&#xff08;\u5982 BOSS \u76f4\u8058\u7c7b\u4ea7\u54c1&#xff09;\u4e2d&#xff0c;\u4f01\u4e1a\u7aef\u6ce8\u518c\u548c\u666e\u901a\u7528\u6237\u6ce8\u518c\u6709\u672c\u8d28\u533a\u522b&#xff1a;\u4f01\u4e1a\u4e0d\u662f\"\u586b\u4e2a\u8d26\u53f7\u5bc6\u7801\u5c31\u80fd\u7528\"&#xff0c;\u800c\u662f\u5fc5\u987b\u63d0\u4ea4\u8425\u4e1a\u6267\u7167\u3001\u6cd5\u4eba\u8eab\u4efd\u8bc1\u3001\u7edf\u4e00\u793e\u4f1a\u4fe1\u7528\u4ee3\u7801\u7b49\u8d44\u8d28\u6750\u6599&#xff0c;\u7ecf\u8fc7\u5e73\u53f0\u5ba1\u6838\u540e\u624d\u80fd\u53d1\u5e03\u804c\u4f4d\u3002\u672c\u6587\u590d\u76d8\u6211\u6700\u8fd1\u843d\u5730\u7684\u4e00\u4e2a\u4f01\u4e1a\u7aef\u6ce8\u518c\/\u8ba4\u8bc1\u540e\u7aef\u6a21\u5757&amp;#xff0c","og_url":"https:\/\/www.wsisp.com\/helps\/85679.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-07-27T13:09:07+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/85679.html","url":"https:\/\/www.wsisp.com\/helps\/85679.html","name":"\u57fa\u4e8e FastAPI + Tortoise ORM \u7684\u4f01\u4e1a\u7aef\u6ce8\u518c\u8ba4\u8bc1\u6a21\u5757\u8bbe\u8ba1\u4e0e\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-07-27T13:09:07+00:00","dateModified":"2026-07-27T13:09:07+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/85679.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/85679.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/85679.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u57fa\u4e8e FastAPI + Tortoise ORM \u7684\u4f01\u4e1a\u7aef\u6ce8\u518c\u8ba4\u8bc1\u6a21\u5757\u8bbe\u8ba1\u4e0e\u5b9e\u73b0"}]},{"@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\/85679","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=85679"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/85679\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=85679"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=85679"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=85679"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=85679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}