def index(request): headers = { 'Content-Type': 'text/html', } header = response_with_headers(headers) user_id = request.query.get('user_id', -1) user_id = int(user_id) user = User.find(user_id) if user is None: return redirect('/login') # 找到 user 发布的所有 weibo weibos = Tweet.find_all(user_id=user_id) log('weibos', weibos) def weibo_tag(weibo): return '<p>{} from {}@{} <a href="/tweet/delete?id={}">删除</a> <a href="/tweet/edit?id={}">修改</a></p>'.format( weibo.content, user.username, weibo.created_time, weibo.id, weibo.id, ) weibos = '\n'.join([weibo_tag(w) for w in weibos]) body = template('weibo_index.html', weibos=weibos) r = header + '\r\n' + body print(1) return r.encode(encoding='utf-8')
def index(request): headers = { 'Content-Type': 'text/html', } header = response_with_headers(headers) user_id = request.query.get('user_id', -1) user_id = int(user_id) user = User.find(user_id) if user is None: return error(request) # 找到 user 发布的所有 weibo weibos = Tweet.find_all(user_id=user_id) for w in weibos: w.load_comments() log('weibos', weibos) body = template('weibo_index.html', weibos=weibos, user=user) r = header + '\r\n' + body return r.encode(encoding='utf-8')