Exemple #1
0
def home():
    if session.get('islogin') is None:
        username = request.cookies.get('username')
        password = request.cookies.get('password')
        if username != None and password != None:
            user = User()
            result = user.find_by_username(username)
            if len(result) == 1 and result[0].password == password:
                session['islogin'] = '******'
                session['userid'] = result[0].userid
                session['username'] = username
                session['nickname'] = result[0].nickname
                session['role'] = result[0].role

    article = Article()
    result = article.find_limit_with_user(0, 10)
    # print(result, end='---------------\n')
    total = math.ceil(article.get_total_count() / 10)  # 向上取整

    # 以下是在首页添加侧边栏的内容,side-jinja2.html中使用到,但是这种方式有一个缺陷:
    # 需要在每个HTML页面中引用引用一下代码,重复率高,改良版在:side.html中
    last, most, recommended = article.find_most_recommended()
    return render_template('index-base.html',
                           result=result,
                           page=1,
                           total=total,
                           last=last,
                           most=most,
                           recommended=recommended)
Exemple #2
0
def paginate(page):
    start = (page - 1) * 10
    article = Article()
    result = article.find_limit_with_user(start, 10)
    total = math.ceil(article.get_total_count() / 10)  # 向上取整
    return render_template('index-base.html',
                           result=result,
                           page=page,
                           total=total)
Exemple #3
0
def home():
    article = Article()
    result = article.find_limit_with_user(0, 10)
    total = math.ceil(article.get_total_count() / 10)  # 总页数
    last, most = article.last_most()
    return render_template('index.html',
                           result=result,
                           page=1,
                           total=total,
                           last=last,
                           most=most)