FastAPI学习
-
保存前端上传的文件
参考:https://geek-docs.com/fastapi/fastapi-questions/205_fastapi_how_to_save_uploadfile_in_fastapi.html
参考:https://www.php.cn/faq/584389.html
参考:https://blog.csdn.net/xys430381_1/article/details/123890134 -
集成数据库
参考:https://blog.csdn.net/weixin_51407397/article/details/131152251
执行原生sql:https://blog.csdn.net/dangsh_/article/details/107158470
参考:https://blog.csdn.net/wtt234/article/details/121144424 -
用户验证
参考:https://blog.csdn.net/wisdom_lp/article/details/132069607
参考: https://www.cnblogs.com/puffer/p/16417064.html
参考:https://www.cnblogs.com/xiao-xue-di/p/15770937.html -
文件下载
参考:https://www.cnblogs.com/bitterteaer/p/17581746.html
参考:https://blog.csdn.net/weixin_44198965/article/details/121783870
# 后端
@router.get('/download_file/{table_name}')
def download_cash(table_name=Path(), conn=pd_conn,current_user: Dict = Depends(get_current_user)):
# 从数据库中读取数据
# df = pd.read_sql_table(table_name, conn)
# 保存数据到本地
# df.to_excel(f'upload/{table_name}.xlsx', index=False)
# 指定文件类型为excel
headers = {
'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
}
headers={}
# 返回文件
return FileResponse(f'upload/{table_name}.xlsx', headers=headers)
// 前端
// 相关依赖:axios,js-file-download
const downloadFile = (table) => {
console.log(table)
// 下载文件
return axios.get('/download_file/' + table,{
responseType: 'blob',
});
}
const handleDownload = async (table) => {
let res = await downloadFile(table)
fileDownload(res, table + '.xlsx')
}
-
流式输出
参考:https://blog.csdn.net/qq_33211006/article/details/130897348
参考:https://blog.csdn.net/wangsenling/article/details/130911465 -
导包问题 attempted relative import with no known parent package
参考:https://blog.csdn.net/qq_41767116/article/details/120408040
浙公网安备 33010602011771号