问题描述
对于我的论坛,我尝试使用html上传文件:
< form action =profiles.py方法= POST >
< label class =labelOnefor =pics>更改您的个人资料图片< / label>
< input type =filename =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
的文件,然后将数据写入它(这应该是图像)。
然而由于某种原因,我没有形象。
接下来应该怎么办? 设置 enctype
您的表单到 multipart / form-data
< form action =profiles.pymethod =postenctype =multipart / form-data>
For my forum, I tried uploading a file with html using:
<form action="profiles.py" method="post">
<label class="labelOne" for="pics">Change your Profile pic </label>
<input type="file" name="uploadField" />
My python function takes that file, creates a file under userprofiles, and writes the data to it:
file = open('../data/accounts/userprofiles/'+str(form['name'].value)+'/'+'profilepics', 'w+')
file.write(str(form.getvalue('uploadField')))
file.close()
So, If I want burger.jpg
to be my picture, I upload it, python takes that and creates a file with that name burger.jpg
using w+
and then it writes the data to it(which should be the image).
However for some reason, I get no image.
What should I try next?
Set the enctype
of your form to multipart/form-data
<form action="profiles.py" method="post" enctype="multipart/form-data">
这篇关于上传html文件并使用python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!