def get(self): todos_query = Todo.all().order('-date') todos = todos_query.fetch(10) template_values = { 'todos' : todos } path = os.path.join(os.path.dirname(__file__), 'index.html') self.response.out.write(template.render(path, template_values))
def index(request): """ todo 首页的路由函数 """ headers = { 'Content-Type': 'text/html', } todo_list = Todo.all() # 下面这行生成一个 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-8')
def root(): todos = Todo.all() return render("home", todos=todos)
def index(request): todo_list = Todo.all() body = template('simple_todo_index.html', todos=todo_list) return http_response(body)