Build a CRUD App with SQLAlchemy - Create a ToDo App

Steps:

  1. 创建一个文件夹
  2. 在文件夹下,create a python file, named “app.py”
from flask import Flask, render_template

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html', data=[{
    
    
        'description': 'Todo 1'
    }, {
    
    
        'description': 'Todo 2'
    }, {
    
    
        'description': 'Todo 3'
    }])

  1. In the project folder, create a new folder named “templates”. Under the templates folder, create an index.html file.
<!DOCTYPE html>
<html>
    <head>
        <title>Todo app</title>
    </head>
    <body>
        <ul>
            {
    
    % for d in data %}
                <li>
                    {
    
    {
    
     d.description }}
                </li>
            {
    
    % endfor %}
        </ul>
    </body>
</html>
  1. Run the app.py file with this command:
$ FLASK_APP=app.py FLASK_DEBUG=true flask run
  1. 得到的结果
    请添加图片描述

猜你喜欢

转载自blog.csdn.net/BSCHN123/article/details/121313624