我有一个网络表单,允许人们上传他们的简历并输入他们的电子邮件,一旦提交,就会通过电子邮件将信息发送给我(简历作为电子邮件附件)。它在本地工作,但在生产中导致错误 - 只是说“内部服务器错误”。它在 Heroku / Flask 上,我正在使用 Flask Mail 发送电子邮件。
这是代码。我的预感是恢复路径没有在生产中被选中,但我不确定。
app.config["UPLOAD_FOLDER"] = "app/resumes/"
# --------------> Cold Resume Submission
@app.route('/', methods=["GET", "POST"])
def homepage():
if request.method == 'GET':
return render_template('home.html')
else:
cold_email = request.form["cold_email"]
file = request.files['cold_resume']
if file and allowed_file(file.filename) and cold_email:
filename = secure_filename(file.filename)
file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
print "file_path", file_path
file.save(file_path)
send_email(subject="Cold Resume...",
sender="LHV TalentTracker",
recipients=email_to_admin,
html_body="Cold Application from Homepage from {0}".format(cold_email),
attachment_path=file_path)
os.remove(file_path)
else:
confirmation = "File or Email invalid"
return render_template("confirmation.html", confirmation=confirmation)
confirmation = "Thanks, We'll be in touch!"
return render_template("confirmation.html", confirmation=confirmation)
- - - 更新 - -
我将所有内容都包装在 try / except 块中并收到以下错误...
homepage email error: <type 'exceptions.Exception'> [Errno 2] No such file or directory: 'app/resumes/Suraj_Kapoor_-_Cover_Letter.pdf' <type 'exceptions.IOError'>
...这证实了我怀疑文件路径没有被拾取,但我不清楚它有什么问题。我确实有一个app/resumes
文件夹。