在下面的代码中,我有两个语句1.方法= ['GET','POST']和2. request.method =='POST'这两个语句执行什么操作

时间:2019-11-02 08:43:56

标签: flask-sqlalchemy

我无法正确理解1.methods = ['GET','POST']和2.request.method =='POST'

所执行的操作
@app.route("/contact",methods = ['GET','POST'])
def contact1():
        if(request.method == 'POST'):
            '''adding entery to database'''
            name = request.form.get('name')
            email = request.form.get('email')
            phone = request.form.get('phone')
            message = request.form.get('message')
            entry = Contacts(name = name,email = email,msg=message,phone_num = phone,date = datetime.now())
            db.session.add(entry)
            db.session.commit()
            mail.send_message('New message from '+ name,
                              sender = email,
                              recipients = [params['gmail-user']],
                              body = message + "\n" + phone
                              )
        return render_template('contact.html',params = params)

0 个答案:

没有答案