如何在Flask中提交AMP表格?

时间:2019-05-07 17:09:41

标签: python flask amp-form

我有我的烧瓶网站和amp-html布局。当我尝试提交表单时,出现以下错误: “表单提交失败:错误:响应必须包含AMP-Access-Control-Allow-Source-Origin标头。”

任何解决此问题的想法? 任何帮助将不胜感激!

烧瓶应用程序:

from flask import Flask, render_template, request, jsonify

app = Flask(__name__)

@app.route('/', methods=['GET','POST'])
def index():

    if "submit" in request.form:
        name = request.form['name']
        email = request.form['email']
        return render_template('form.html',name=name,email=email)

    return render_template('form.html')

@app.route("/insert", methods=['POST'])
def create():

    return jsonify({'data':{"Content-type": "application/json",
        "Access-Control-Allow-Credentials": "true",
        "Access-Control-Allow-Origin":"live.cdn.ampproject.org",
        "AMP-Access-Control-Allow-Source-Origin": "http://127.0.0.1:5000/.cdn.ampproject.org", 
        "AMP-Control-Expose-Headers": "AMP-Access-Control-Allow-Source-Origin",
        "AMP-Redirect-To": "http://127.0.0.1:5000/",
        "AMP-Same-Origin":"true",
        "Access-Control-Expose-Headers": "AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin"}})

if __name__ == '__main__':
    app.secret_key='secret123'
    app.run(debug=True)

和我的form.html

<form method="POST" action-xhr="/insert" target="_top">
   <input type="text" name="name" placeholder="Name" autocomplete="off" autofocus value="" spellcheck="false">
   <input type="hidden" name="email" placeholder="Email" autocomplete="off" autofocus value="" >
   <input type="submit" value="Submit" name="submit">
</form>

0 个答案:

没有答案