编辑页模板 edit.html
1. 修改 TD_Simple 类 GET 方法
将json.dumps 修改为render.edit
class TD_Simple: #针对单个待办事件处理类
def GET(self,id):
'''
按ID查询返回结果
:param id:
:return:
'''
todo = get_by_id(id)
if not todo:
return json.dumps({'error':'没找到这条记录'})
post_data = formatField(todo)
#web.header('Content-Type', 'application/json')
#return json.dumps(post_data)
return render.edit(todo)
2. templates下编辑 edit.html
$def with(todo)
$:render.header()
<div class="box post">
<h2>修改</h2>
<p>
<input type="text" name="title" class="long_txt" value="$todo['title']" />
</p>
<p>
<input type="submit" onclick="editTD('$todo['_id']')" value="提交" />
</p>
</div>
<script language=javascript>
function editTD(obj){
alert(obj);
$$.ajax({
type: "PATCH",
url:"/TodoLists/"+obj,
data:{
'title':$$(".long_txt").val()
},
success:function(result){
alert("数据: \n" + result + "\n" );
window.location.href ='#';
},
error:function() {
alert(arguments[1]);
//alert("异常!");
}
});
};
</script>
$:render.foot()