我一直在研究我在Heroku上托管的烧瓶应用程序。具体来说,我正在使用Flask-Mail发送用户希望用来与我联系的电子邮件的联系页面上工作。我按照说明设置了环境并设置了表单:
在 init .py 中
app.config["MAIL_SERVER"] = "smtp.gmail.com"
app.config["MAIL_PORT"] = 465
app.config["MAIL_USE_SSL"] = True
app.config["MAIL_USERNAME"] = <my email>
app.config["MAIL_PASSWORD"] = <my password>
in contact.html
{% extends "base.html" %}
{% block body%}
<div class = 'jumbotron'>
<div class = 'span7 center'>
<div class="login">
<div class="row">
<div class="col-lg-6 col-lg-offset-3">
<div class="span7 center"><legend><h2>Contact</h2></legend></div>
<!--If form submission successful, message is sent to site email-->
{% if success %}
<p>Thank you for your message. We'll get back to you shortly.</p>
{% else %}
<!--Displays error message-->
{% for message in form.name.errors %}
<div class="flash">{{ message }}</div>
{% endfor %}
{% for message in form.email.errors %}
<div class="flash">{{ message }}</div>
{% endfor %}
{% for message in form.subject.errors %}
<div class="flash">{{ message }}</div>
{% endfor %}
{% for message in form.message.errors %}
<div class="flash">{{ message }}</div>
{% endfor %}
<!--Generates form from forms.py & routes.py-->
<form class="bs-example form-horizontal" action="{{ url_for('contact') }}" method=post>
</fieldset>
{{ form.hidden_tag() }}
{{ form.name.label }}
{{ form.name }}
{{ form.email.label }}
{{ form.email }}
{{ form.subject.label }}
{{ form.subject }}
{{ form.message.label }}
{{ form.message }}
{{ form.submit }}
</form>
{% endif %}
</div>
</div>
</div>
</div>
</div>
{% endblock %}
麻烦的是,一切都在本地运行良好(当使用Foreman时),但是当我将代码推送到Heroku时,它根本不起作用!这是我的日志:
2014-09-12T18:46:08.261454+00:00 heroku[router]: at=info method=GET path="/press" host=swattank.herokuapp.com request_id=fb0318af-ab0f-4cd0-abec-944a919ac469 fwd="130.58.174.233" dyno=web.1 connect=4ms service=46ms status=200 bytes=624
2014-09-12T18:46:14.800621+00:00 heroku[router]: at=info method=POST path="/contact" host=swattank.herokuapp.com request_id=b2c66ffd-4cba-4e45-8e4b-193256ce3fa3 fwd="130.58.174.233" dyno=web.1 connect=1ms service=14ms status=200 bytes=1074
2014-09-12T18:46:06.813709+00:00 heroku[router]: at=info method=GET path="/static/js/bootstrap.min.js" host=swattank.herokuapp.com request_id=58d6eb4b-4037-496c-8d36-3dcec4b4fd90 fwd="130.58.174.233" dyno=web.1 connect=1ms service=8ms status=200 bytes=962
2014-09-12T18:49:22.795276+00:00 heroku[router]: at=info method=GET path="/" host=swattank.herokuapp.com request_id=786e0a17-88a1-42be-9c62-fb092fa6ec67 fwd="54.242.148.183" dyno=web.1 connect=2ms service=7ms status=200 bytes=396
2014-09-12T18:53:43.292848+00:00 heroku[router]: at=info method=POST path="/contact" host=swattank.herokuapp.com request_id=bd665070-c7a7-460c-8c8a-2a08e48bbf95 fwd="130.58.174.233" dyno=web.1 connect=1ms service=10ms status=200 bytes=1174
我真的很感激任何帮助!