【发布时间】:2020-06-30 13:44:37
【问题描述】:
有一个输入表单,我可以从中获取页面上的文档(pdf、txt、png 等)并将其发送到电子邮件。除了一件事之外,一切都有效。我只能从所有代码所在的某个目录中选择文档,如果我从另一个文件夹中选择我的文档,我会收到错误No such file or directory。如何从任何文件夹中选择 doc?
python:
@app.route('/', methods=['GET','POST'])
def profile():
file = request.form['file']
password = "mypass"
msg['From'] = "mymail"
msg['To'] = "anothermail"
msg['Subject'] = "Subject"
msg = MIMEMultipart()
file_to_send = MIMEApplication(open(file, 'rb').read())
file_to_send.add_header('Content-Disposition', 'attachment', filename=file)
msg.attach(file_to_send)
server = smtplib.SMTP('smtp.gmail.com: 587')
server.starttls()
server.login(msg['From'], password)
server.sendmail(msg['From'], msg['To'], msg.as_string())
return render_template('profile.html', file=file)
profile.html:
<input type='file' class="form-control" name="file" id="uploadPDF">
<button class="btn btn-primary send">
Send
</button>
【问题讨论】:
-
你能发布你看到的实际追溯吗?
-
@KenKinder,当然。请再次检查。当我从另一个文件夹中选择其他文档的图像时,就会发生这种情况
标签: python html python-3.x flask