You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在FastHTML中为Input元素添加webkitdirectory属性以获取文件夹名?

解决FastHTML生成带webkitdirectory属性的文件输入框问题

要生成包含webkitdirectory属性的<input type="file" webkitdirectory />,在FastHTML中需以布尔值的方式传递该属性,而非空字符串。

修改后的代码如下:

Input(type="file", webkitdirectory=True)

生成的对应HTML为:

<input type="file" webkitdirectory>

原因在于:FastHTML对布尔属性的处理逻辑是,当属性值设为True时,会仅保留属性名(符合HTML布尔属性的规范);若传递空字符串,框架会判定该属性无需渲染,进而将其过滤。

内容的提问来源于stack exchange,提问作者Ximo Dante

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 05:57:00