def blog_view(): ''' :param page: 获取分页数 :param user_id 用户ID :return: 返回读取的结果 ''' page = request.values.get('page', '1') user_id = request.values.get('user_id', None) page_index = get_page_index(page) if user_id: num = Blog.find_number('count(id)', where='user_id=?', args=(user_id,)) else: num = Blog.find_number('count(id)') p = Page(num, page_index, page_size=PRE_PAGE_NUMBER) if num == 0: json.dumps(dict(page=p, blogs=()), ensure_ascii=False, default=lambda o: o.__dict__).encode('utf-8') if user_id: blogs = Blog.find_all('user_id=?', [user_id], orderBy='created_at desc', limit=(p.offset, p.limit)) else: blogs = Blog.find_all(orderBy='created_at desc', limit=(p.offset, p.limit)) return json.dumps(dict(page=p, blogs=blogs), ensure_ascii=False, default=lambda o: o.__dict__).encode('utf-8')
def index(): page = request.values.get('page', '1') page_index = get_page_index(page) if g.user is not None and g.user.is_authenticated: return render_template('index.html', user=g.user, page_index=page_index) return render_template('index.html', page_index=page_index)
def blog_manage(): # blogs = Blog.find_all('user_id = ?', g.user.id) page = request.values.get('page', '1') page_index = get_page_index(page) return render_template('blog_manage.html', user=g.user, page_index=page_index)