我有一个网页表单,允许人们上传他们的简历并输入他们的电子邮件,一旦提交,就会将信息通过电子邮件发送给我(简历作为电子邮件附件)。它在本地工作但在生产中导致错误 - 只是说"内部服务器错误"。它在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)
------ ---- UPDATE
我将所有内容都包含在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
文件夹。