def index(request): """ 主页的处理函数, 返回主页的响应 """ todo_list = Todo.all() body = template('simple_todo_index.html', todos=todo_list) return http_response(body)
def index(request): """ _todo 首页的路由函数 """ todo_list = Todo.all() body = template('simple_todo_index.html', todos=todo_list) return http_response(body)
def index(request): """ 主页的处理函数, 返回主页的响应 """ header = 'HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n' todo_list = Todo.all() body = template('simple_todo_index.html', todos=todo_list) r = header + '\r\n' + body return r.encode(encoding='utf-8')
def index(request): header = 'HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n' #session_id = request.cookies.get('user','') #user_id = session.get(session_id) todo_list = Todo.all() #log('index debug', user_id, todo_list) body = template('todo_index.html', todos=todo_list) r = header + '\r\n' + body return r.encode(encoding='utf-8')
def index(request): """ 主页的处理函数, 返回主页的响应 """ # 首先拿到所有的todo数据 todo_list = Todo.all() # 用 template 函数打开 simple_todo_index.html 页面,把 todo_list 传进去,使用模版渲染网页 """ template函数接受一个路径和一系列参数 读取模板并渲染返回 """ body = template('simple_todo_index.html', todos=todo_list) # return http_response(body)
def route_index(request): headers = { 'Content-Type': 'text/html', } header = response_with_headers(headers) todos = Todo.all() def todo_tag(t): status = t.status() return '<p>{} {}@{} 状态: {} <a href="/todo/complete?id={}">完成</a></p>'.format( t.id, t.content, t.created_time, status, t.id) todo_html = '\n <br>\n '.join([todo_tag(w) for w in todos]) body = template('todo_index.html', todos=todo_html) r = header + '\r\n' + body return r.encode(encoding='utf-8')
def todo(request): uname = get_cookie(request) u = User.find_by(username=uname) if u is None: return director('/login') body = template('todo.html') todos = [] log('Todo.all', Todo.all()) for t in Todo.find_all(user_id=u.id): a = '<a href="/todo/edit?id={}">编辑</a>'.format(t.id) b = '<a href="/todo/todo_delete?id={}">删除</a>'.format(t.id) s = '<h3>{}: {} {} {}</h3>'.format(t.id, t.username, a, b) todos.append(s) result = ''.join(todos) body = body.replace('{{todos}}', result) header = 'HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n' r = header + '\r\n' + body return r.encode('utf-8')
def route_index(): headers = { 'Content-Type': 'text/html', } header = response_with_header(headers) todos = Todo.all() def todo_tag(todo): status = todo.status() tag = ('<p class="{}">{} {} @ {}' '<a href="/todo/complete?id={}">完成</a></p>') return tag.format( status, todo.id, todo.content, todo.created_time, todo.id, ) todo_html = '\n'.join([todo_tag(todo) for todo in todos]) body = template('todo_index.html', todos=todo_html) r = header + '\r\n' + body return r.encode(encoding='utf-8')
def todo_list(): """Simple todo page.""" form = TodoForm() todos = Todo.all().order('-created_at') return render_template('todo.html', form=form, todos=todos)
def retrieve_todos(): content = json.dumps([todo.to_dict() for todo in Todo.all()]) response = make_response(content) response.mimetype = 'application/json' return response
from models import Todo t = Todo({}) print(t.all())