使用Python文件导入Flask问题

时间:2013-10-25 03:12:56

标签: python email flask flask-extensions

当我运行下面的文件时,我收到此错误:

Traceback (most recent call last):
  File "/Users/msk/bssproject/sendmail.py", line 1, in <module>
    from flask import Flask, render_template, request, flash
ImportError: No module named flask
[Finished in 0.0s with exit code 1]

我已经确认Flask已正确安装,因此我没有安装烧瓶。

这是文件:

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 = 'usernname@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()

0 个答案:

没有答案