【问题标题】:python flask | use html input in different file蟒蛇烧瓶|在不同的文件中使用 html 输入
【发布时间】:2021-05-13 22:20:11
【问题描述】:

所以在我使用烧瓶将 HTML 输入存储在 python 变量中之后。如何在不同的路径文件中使用此变量,即:[我已将相应 LOC 旁边的问题注释掉]

/example.html
<input type=text name=inputStr>
<button type=submit>Submit</button>


/main.py
@app.route("/example", methods=['POST'], ['GET'])
def example():
    if request.method=='POST':
        string=request.form["inputStr"]  # suppose this is the variable i'd like to use in a diff file
    return render_template("example.html")


/examplefile.py   
from main import string  # this does not seem to work, as you can see i'd like to import the string here

examplestring = string
print(examplestring)

【问题讨论】:

    标签: python html flask import


    【解决方案1】:

    试试:

        /main.py
    @app.route("/example", methods=['POST'], ['GET'])
    def example():
        if request.method=='POST':
            global string=request.form["inputStr"]  # suppose this is the variable i'd like to use in a diff file
        return render_template("example.html")
    
    
    /examplefile.py   
    from main import example
    examplestring = example.string
    

    如果它不起作用,这篇文章应该可以帮助你:

    How to share global variables between files in Python

    【讨论】:

      猜你喜欢
      • 2023-03-26
      • 2014-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-28
      • 1970-01-01
      相关资源
      最近更新 更多