flask模板语言

cooolr 于 2023-03-20 发布
from flask import Flask, render_template

app = Flask(__name__)

@app.route('/')
def index():
    data = {
        'title': 'My Website',
        'heading': 'Welcome to my website!',
        'content': 'This is a simple website generated using Flask and Flash templates.',
        'items': ['Item 1', 'Item 2', 'Item 3']
    }
    return render_template('index.html', **data)

templates/index.html

<!DOCTYPE html>
<html>
  <head>
    <title>{ { title } }</title>
  </head>
  <body>
    <h1>{ { heading } }</h1>
    <p>{ { content } }</p>
    <ul>
      { { for item in items } }
      <li>{ { item } }</li>
      { { endfor } }
    </ul>
  </body>
</html>