FastAPI学习

  1. 保存前端上传的文件
    参考: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

  2. 集成数据库
    参考: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

  3. 用户验证
    参考: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

  4. 文件下载
    参考: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')
}
  1. 流式输出
    参考:https://blog.csdn.net/qq_33211006/article/details/130897348
    参考:https://blog.csdn.net/wangsenling/article/details/130911465

  2. 日志
    参考:https://www.51cto.com/article/707542.html

  3. 导包问题 attempted relative import with no known parent package
    参考:https://blog.csdn.net/qq_41767116/article/details/120408040

posted on   朝朝暮Mu  阅读(39)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示