示例#1
0
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)
示例#2
0
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)
示例#3
0
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)
示例#4
0
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)
示例#5
0
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网页作为模板
示例#6
0
文件: views.py 项目: ghostloda/-Flask
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)
示例#7
0
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)
示例#8
0
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)
示例#9
0
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)
示例#10
0
文件: views.py 项目: 2lusy/learndemo
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)
示例#11
0
文件: views.py 项目: ghostloda/-Flask
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)
示例#12
0
文件: views.py 项目: ghostloda/-Flask
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)
示例#13
0
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)
示例#14
0
文件: views.py 项目: 2lusy/learndemo
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)
示例#15
0
def index():
    #首页
    images = Image.query.order_by(db.desc(Image.id)).limit(5).all()

    return render_template('index.html', images=images)
示例#16
0
def index():
    images = Image.query.order_by(db.desc(Image.id)).limit(10).all()
    return render_template('index.html', images = images)
示例#17
0
文件: views.py 项目: MrKKKKID/nowcode
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)
示例#18
0
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()