Skip to content

Commit 163ed35

Browse files
committed
代码优化;个别地方注释和错别字纠正
1 parent 30240a9 commit 163ed35

2 files changed

Lines changed: 4 additions & 19 deletions

File tree

pydantic_tutorial.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,4 @@ class Config:
117117

118118
print(CompanyModel.from_orm(co_orm))
119119

120-
print("\033[31m6. --- 错误处理 ---\033[0m")
121-
122-
user_data = {"id": "error", "signup_ts": "2020-12-22 12 22", "friends": [1, 2, 3]} # id是字符串 是错误的
123-
124-
try:
125-
User(**user_data)
126-
except ValidationError as e:
127-
print(e)
128-
print("- " * 30)
129-
print(e.json())
130-
print("- " * 30)
131-
print(e.errors())
132-
133-
print("\033[31m7. --- Pydantic支撑的字段类型 ---\033[0m") # 官方文档:https://pydantic-docs.helpmanual.io/usage/types/
120+
print("\033[31m6. --- Pydantic支撑的字段类型 ---\033[0m") # 官方文档:https://pydantic-docs.helpmanual.io/usage/types/

run.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
)
2525

2626
# mount表示将某个目录下一个完全独立的应用挂载过来,这个不会在API交互文档中显示
27-
app.mount('/static', StaticFiles(directory='./coronavirus/static'), name='static') # .mount()不要在分路由APIRouter().mount()调用,模板会报错
27+
app.mount(path='/static', app=StaticFiles(directory='./coronavirus/static'), name='static') # .mount()不要在分路由APIRouter().mount()调用,模板会报错
2828

2929

3030
# @app.exception_handler(StarletteHTTPException) # 重写HTTPException异常处理器
@@ -48,7 +48,7 @@
4848

4949

5050
@app.middleware('http')
51-
async def add_process_time_header(request: Request, call_next): # call_next将接收request请求最为参数
51+
async def add_process_time_header(request: Request, call_next): # call_next将接收request请求做为参数
5252
start_time = time.time()
5353
response = await call_next(request)
5454
process_time = time.time() - start_time
@@ -59,10 +59,8 @@ async def add_process_time_header(request: Request, call_next): # call_next将
5959
app.add_middleware(
6060
CORSMiddleware,
6161
allow_origins=[
62-
"http://127.0.0.1.tiangolo.com",
63-
"https://127.0.0.1.tiangolo.com",
6462
"http://127.0.0.1",
65-
"http://127.0.0.1:8080",
63+
"http://127.0.0.1:8080"
6664
],
6765
allow_credentials=True,
6866
allow_methods=["*"],

0 commit comments

Comments
 (0)