【问题标题】:Passing html form input values in python flask [duplicate]在python烧瓶中传递html表单输入值[重复]
【发布时间】:2018-06-08 16:13:14
【问题描述】:

所以我有一个 html 表单输入,基本上我想获取我输入的值并将其传递到我的 app.route(/sometext/inputvalue)

 @app.route('/inputvalue')
def index():
  return render_template('index.html')

【问题讨论】:

    标签: python html flask


    【解决方案1】:

    您需要使用POST GET 方法捕获应用程序的表单请求。所以为此你需要一个登录方法。 像这样的。

    # you don't need to redirect the template
    from flask import Flask, redirect, url_for, request
    @app.route('/login', methods=['POST', 'GET'])
    def login():
    
        if request.method == 'POST':
            user = request.form['Email'] # suppose you have a email and password field
            passe = request.form['passw']
    
            return redirect(url_for('index', inputvalue=user)) # then you can pass email or pass
    

    在这些事情完成并且服务器运行之后,打开你的 html 文件 并填写表格。您可以通过

    查看重定向的值
    @app.route('/inputvalue')
    def index(inputvalue):
      return ('hey' + inputvalue)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-22
      • 2020-07-30
      • 1970-01-01
      • 1970-01-01
      • 2018-02-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多