1.将字符串传到前端页面

   在user.py中做简单修改即可Flask中视图函数传数据到前端页面@pythonweb_blue.route('/user') def user(): data = '我是小可爱' return render_template('index.html',data = data)
Flask中视图函数传数据到前端页面

<!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <h1>{{data}}</h1>
    </body>
    </html>

2.传多个数据时,先把数据写成字典之后再传入,举例说明。

Flask中视图函数传数据到前端页面

 @pythonweb_blue.route('/user')
    def user():
        context2 = {
            'username': 'abc',
            'age': 18,
            'sex': '男'
        }
        return render_template('index.html',**context2)```

index.html

  <html lang="en">
  <head>
      <meta charset="UTF-8">
      <title>Title</title>
  </head>
  <body>
  <h1>{{username}}</h1>
  </body>
  </html>
  





相关文章:

  • 2021-06-22
  • 2022-01-23
  • 2021-10-28
  • 2021-05-04
  • 2022-12-23
  • 2021-06-27
  • 2021-08-26
猜你喜欢
  • 2021-06-02
  • 2021-09-01
  • 2022-12-23
  • 2021-10-14
  • 2022-12-23
  • 2022-12-23
  • 2021-07-20
相关资源
相似解决方案