예제 #1
0
def index(request):
    """
    todo首页,查看所有的todo
    """
    headers = {
        'Content-Type': 'text/html'
    }
    # 拿到 所有todo
    todo_list = Todo.all()
    # 生成todo的html
    todo_html = ''.join(['<h3>{}: {}</h3>'.format(t.id, t.title) for t in todo_list])
    # 替换模板文件中的字符串
    body = template('todo_index.html')
    body = body.replace('{{todos}}', todo_html)
    header = response_with_headers(headers)
    r = header + '\r\n' + body
    return r.encode(encoding='utf')
예제 #2
0
def index(request):
    todo_list = Todo.all()
    body = templates('simple_todo_index.html', todos=todo_list)
    return http_response(body)