导入Flask语法错误消息

时间:2013-10-31 18:46:56

标签: python templates flask

这里有什么问题?我正在尝试在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]

sendmail.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()

1 个答案:

答案 0 :(得分:0)

  1. 确保将Flask安装在您的PC中
  2. 我认为问题出在你制作路由器时
  3. 您可以使用此

    进行测试
    @app.route("/home")
    
    def home():
    __ ....    
    __ ....    
    __ return