def index(): images = Image.query.order_by(db.desc(Image.id)).limit(10).all() paginate = Image.query.order_by(db.desc(Image.id)).paginate( page=1, per_page=10, error_out=False) return render_template('index.html', images=paginate.items, has_next=paginate.has_next)
def index_image(page, per_page): paginate = Image.query.order_by_by(db.desc(Image.id)).paginate( page=page, per_page=per_page, error_out=False) map = {'has_next': paginate.has_next} images = [] for image in paginate.items: comments = [] for i in range(0, min(2, len(image.comments))): comment = image.comments[i] comments.append({ 'username': comment.user.username, 'user_id': comment.user_id, 'content': comment.content }) imgvo = { 'id': image.id, 'url': image.url, 'comment_count': len(image.comments), 'user_id': image.user_id, 'head_url': image.user.head_url, 'create_date': str(image.created_date), 'comments': comments } images.append(imgvo) map['images'] = images return json.dumps(map)
def image(image_id): image = Image.query.get(image_id) if (image is None): return redirect('/') comments = Comment.query.filter_by(image_id=image_id).order_by( db.desc(Comment.id)).limit(20).all() return render_template('pageDetail.html', image=image, comments=comments)
def index_paginate(page_num, per_page): images = Image.query.order_by(db.desc(Image.id)).paginate( page=page_num, per_page=per_page, error_out=False) map = {'has_next': images.has_next} image = [] for item in images.items: comment_user_username = [] comment_user_id = [] comment_content = [] for comments_i in item.comments: comment_user_username.append(comments_i.user.username) comment_user_id.append(comments_i.user.id) comment_content.append(comments_i.content) imgov = { 'image_user_id': item.user.id, 'image_created_date': str(item.created_date), 'image_user_head_url': item.user.head_url, 'image_user_username': item.user.username, 'image_id': item.id, 'image_url': item.url, 'image_comments_length': len(item.comments), 'comment_user_username': comment_user_username, 'comment_user_id': comment_user_id, 'comment_content': comment_content } image.append(imgov) map['images'] = image return json.dumps(map)
def image(image_id): image = Image.query.get(image_id) # 用的单数,就一张图片,获取到了图片的变量 if image == None: return redirect('/') # 重定向的页面跳转,在class_02讲过;如果图片为空,则重定向回首页; comments = Comment.query.filter_by(image_id=image_id).order_by( db.desc(Comment.id)).limit(20).all() return render_template('pageDetail.html', image=image, comments=comments) # 否则就进入图片详情页;传入.html网页作为模板
def user_images(user_id,page,per_page): paginate = Image.query.filter_by(user_id=user_id).order_by(db.desc(Image.id)).paginate(page=page,per_page=per_page,error_out=False) map={'has_next':paginate.has_next} images=[] for image in paginate.items: imgvo = {'id':image.id,'url':image.url,'comment_count':len(image.comments)} images.append(imgvo) map['images']=images return json.dumps(map)
def user_images(user_id, page, per_page): paginate = Image.query.filter_by(user_id=user_id).order_by(db.desc(Image.id)).paginate(page=page, per_page=per_page, error_out=False) map = {'has_next': paginate.has_next} images = [] for image in paginate.items: imgvo = {'id': image.id, 'url': image.url, 'comment_count': len(image.comments)} images.append(imgvo) map['images'] = images return json.dumps(map)
def profile(user_id): print "user_id", user_id user = User.query.get(user_id) print "111111" if user == None: return redirect('/') print "22222" images = Image.query.filter_by(user_id=user_id).order_by(db.desc(Image.id)) print "3333" return render_template('profile.html', user=user, images=images)
def profile(user_id): user = User.query.get(user_id) if user is None: return redirect('/') paginate = Image.query.filter_by(user_id=user_id).order_by( db.desc(Image.id)).paginate(page=1, per_page=3, error_out=False) return render_template('profile.html', user=user, images=paginate.items, has_next=paginate.has_next)
def index_images(page, per_page): paginate = Image.query.order_by(db.desc(Image.id)).paginate(page=page, per_page=per_page, error_out=False) map = {'has_next': paginate.has_next} images = [] for image in paginate.items: comments = [] for i in range(0, min(2, len(image.comments))): comment = image.comments[i] comments.append({'username':comment.user.username, 'user_id':comment.user_id, 'content':comment.content}) imgvo = {'id': image.id, 'url': image.url, 'comment_count': len(image.comments), 'user_id': image.user_id, 'head_url':image.user.head_url, 'created_date':str(image.created_date), 'comments':comments} images.append(imgvo) map['images'] = images return json.dumps(map)
def image(image_id): image = Image.query.get(image_id) if image == None: return redirect('/') comments =Comment.query.filter_by(image_id=image_id).order_by(db.desc(Comment.id)).limit(20).all() return render_template('pageDetail.html', image=image,comments=comments)
def index(): paginate=Image.query.order_by(db.desc(Image.id)).paginate(page=1,per_page=5,error_out=False) return render_template('index.html',images=paginate.items,has_next=paginate.has_next)
def index(): paginate = Image.query.order_by(db.desc(Image.id)).paginate( page=1, per_page=10, error_out=False) return render_template("index.html", images=paginate.items, has_next=paginate.has_next)
def profile(user_id): user = User.query.get(user_id) if user == None: return redirect('/') paginate = Image.query.filter_by(user_id=user_id).order_by(db.desc(Image.id)).paginate(page=1, per_page=3, error_out=False) return render_template('profile.html', user=user, images=paginate.items, has_next=paginate.has_next)
def index(): #首页 images = Image.query.order_by(db.desc(Image.id)).limit(5).all() return render_template('index.html', images=images)
def index(): images = Image.query.order_by(db.desc(Image.id)).limit(10).all() return render_template('index.html', images = images)
def index(): images = Image.query.order_by(db.desc(Image.id)).limit(10).all() #images = Image.query.order_by('-id').limit(10).all() #images = Image.query.order_by('id desc').limit(10).all() return render_template('index.html', images=images)
def show_database(): #print 1, User.query.all() #print 2, User.query.get(3) # primary key = 3 #print 3, User.query.filter_by(id=2).first() #print 4, User.query.order_by(User.id.desc()).offset(1).limit(2).all() print 4, Image.query.order_by(db.desc(Image.id)).limit(10).all()