python todo-list网页实现
开始
先献上代码
todolist.py
from flask import Flask,render_template
todolist = []
app = Flask(__name__)
@app.route('/')
def home():
return render_template('todolist.html')
@app.route('/api/todolist/checkItems',methods=['POST'])
def checkTodo():
return str(todolist),200
@app.route('/api/todolist/delItem/<int:item>',methods=['POST'])
def delTodo(item):
todolist.pop(item)
return ''
@app.route('/api/todolist/addItem/<content>',methods=['POST'])
def addTodo(content):
todolist.append(content)
return ''
app.run()
template/todolist.html
<!DOCTYPE html>
<html>
<head>
<title>todolist日程表</title>
</head>
<body>
<h1>todolist日程表</h1>
创建新的日程new todo:<input type="text" id="newTodo" name="newTodo" /><input type="button" id="submit" value="submit确认" name="submit" />
<br />
<input type="button" id="clear" name="clear" value="删除已完成的delete the finished items">
<br />
<div id="div">
</div>
</body>
<script>