【问题标题】:variable specified in flask not showing up in git pages烧瓶中指定的变量未显示在 git 页面中
【发布时间】:2020-07-09 13:22:05
【问题描述】:

我在我的烧瓶应用程序中指定了一个变量,当模板被渲染时,该变量应该会显示出来。但是,变量本身并没有显示出来,而是在它的位置上显示“{{variable}}”。我该如何解决这个问题。

predictions = linear.predict(x_test)
for x in range(len(predictions)):
     print(predictions[x],x_test[x], y_test[x]) #i got rid of 'y_test[x]

output = predictions[x]

p = Flask(__name__)
Bootstrap(app)


@app.route('/')
def math():
    #return(y)
    return render_template('index.html', variable = output)

if __name__ == "__main__":
    app.run(debug = True)

这是我的索引:

  <section id="services" class="bg-light">
    <div class="container">
      <div class="row">
        <div class="col-lg-8 mx-auto">
          <h2>Here is the prediction for Tesla stock price</h2>
          <p class="lead">Stock prediction: {{variable}}</p>
        </div>
      </div>
    </div>

这里是实时网站:https://amanpuranik.github.io/stock2/ 这里是 github 仓库:https://github.com/amanpuranik/stock2

任何帮助将不胜感激,谢谢。

【问题讨论】:

    标签: python variables github flask


    【解决方案1】:

    documentation中所述:

    flask.render_template(template_name_or_list, **context)

    从具有给定上下文的模板文件夹中呈现一个模板。

    默认模板文件夹是您根目录中的 templates/。所以如果你想渲染它,你需要把 index.html 放到这个模板文件夹中。

    如果您想更改模板文件夹,您可以在创建应用对象时更改参数template_folder,如here 所述。

    【讨论】:

    • 现在看看我的 github repo。我将 index.html 放在模板文件夹中,但它仍然无法正常工作。我做错了什么?
    • 如果您在谈论您的网站,您是否正确更新?因为现在看来是正确的
    • 真的等吗?当我点击我的网站时,除了文本“stock2”和“stock guru”之外什么也看不到。模板本身没有被渲染。正确更新是什么意思?
    • 如您所见,除了“stock2”等文字外,我什么也看不到……我的意思是您明确定义了一条路线“/”。 “/stock2”从何而来?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-31
    • 2020-09-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多