【问题标题】:uploading html files and using python上传 html 文件并使用 python
【发布时间】:2014-04-15 00:27:48
【问题描述】:

对于我的论坛,我尝试使用 html 上传文件:

<form action="profiles.py" method="post">
<label class="labelOne" for="pics">Change your Profile pic </label>
<input type="file" name="uploadField" />

我的 python 函数获取该文件,在 userprofiles 下创建一个文件,并将数据写入其中:

file = open('../data/accounts/userprofiles/'+str(form['name'].value)+'/'+'profilepics', 'w+')
file.write(str(form.getvalue('uploadField')))
file.close()

所以,如果我希望 burger.jpg 成为我的图片,我上传它,python 会使用它并使用 w+ 创建一个名为 burger.jpg 的文件,然后将数据写入其中(应该是图片)。

但是由于某种原因,我没有得到图像。

接下来我应该尝试什么?

【问题讨论】:

    标签: python html


    【解决方案1】:

    将表单的enctype 设置为multipart/form-data

    <form action="profiles.py" method="post" enctype="multipart/form-data">
    

    【讨论】:

      猜你喜欢
      • 2011-08-12
      • 2014-03-04
      • 2012-08-23
      • 1970-01-01
      • 2021-03-28
      • 2020-01-22
      • 2016-01-11
      • 1970-01-01
      • 2020-05-13
      相关资源
      最近更新 更多