1

这里有什么问题?我正在尝试用 Python 编写一个应用程序,它将在网站上的表单上输入的调查数据发送到一个电子邮件地址,该地址可以与用 html 编写的网页一起使用。

错误信息:

  File "/Users/msk/bssproject/sendmail.py", line 2
    from flask import Flask, render_template, request, flash
       ^
SyntaxError: invalid syntax
[Finished in 0.1s with exit code 1]

发送邮件.py:

@app.route("/Users/msk/bssproject/Flask-0.10")
from flask import Flask, render_template, request, flash import flask.views
from flask.forms import ContactForm
from flask.ext.mail import Message, Mail

mail = Mail()

app = Flask(__name__)

mail.init_app(app)

app.config.update( 
DEBUG = True, 
MAIL_SERVER = 'smtp.gmail.com', 
MAIL_PORT = 465, 
MAIL_USE_TLS = False, 
MAIL_USE_SSL = True, 
MAIL_USERNAME = 'username@gmail.com', 
MAIL_PASSWORD = 'password')

mail = Mail(app)

def send_email():
    form = ContactForm()

    if request.method == 'POST':
        if form.validate() == False:
            flash('All fields are required')
        return render_template('feedback.html', form=form)
    else:
        msg = Message(form.subject.data, sender='mlkrgr@gmail.com', recipients=['mlkrgr@gmail.com'])
        msg.body = "feedback.html"      
        send (form.name.data, form.email.data, form.message.data)
        mail.send(msg)
    return 'Form posted'

class Submit(flask.views.MethodView):
    def post(self):
        send_email()
        return flask.render_template('thanks.html')

app.add_url_rule('/',
        view_func=Submit.as_view('submit'),
        methods=["POST"])

app.run()
4

1 回答 1

0
  1. 确保 Flask 已安装在您的 PC 中
  2. 我认为问题出在您制作路由器时

你可以用这个测试

@app.route("/home")

def home():
__ ....    
__ ....    
__ return 
于 2013-11-01T12:25:57.103 回答