如何在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
相关产品推荐
相关产品推荐

