45 - 个人博客项目-16 - 我的相册

1. templstes / user / myphoto.html 新建我的相册页面

        (1). 继承公共模板
{% extends 'base.html' %}
{% block title %}
    相册列表
{% endblock %}
        (2). 编写样式
{% block styles %}
    {{ super() }}
    <style>
        #container {
            padding-top: 30px;
            width: 1000px;
            height: 500px;
            margin: 20px auto;
        }
 
        img {
            width: 50%;
            height: 50%;
        }
 
        #photo {
            text-align: center;
            margin-top: 30px;
        }
    </style>
{% endblock %}
        (3). 编写内容

{% block newcontent %}
    <div id="container">
        {% for photo in photos.items %}
            <div id="photo">
<!--                访问骑牛云上的图片,需要七牛云生成的链接-->
                <img src="http://rveq0tjn6.hn-bkt.clouddn.com/{{ photo.photo_name }}">
            </div>
        {% endfor %}
        <nav aria-label="...">
            <ul class="pager">
                <li class="previous {% if not photos.has_prev %}disabled{% endif %}"><a
                        href="{{ url_for('user.myphoto') }}?page={{ photos.prev_num }}"><span
                        aria-hidden="true">&larr;</span> 上一页</a></li>
 
                <li class="next {% if not photos.has_next %}disabled{% endif %}"><a
                        href="{{ url_for('user.myphoto') }}?page={{ photos.next_num }}">下一页 <span
                        aria-hidden="true">&rarr;</span></a></li>
            </ul>
        </nav>
    </div>
 
 
{% endblock %}

2. apps / user / views.py 编写我的相册函数

# 我的相册
@user_bp.route("/myphoto")
def myphoto():
    # 如果不转成整形,默认是str类型
    page = int(request.args.get('page', 1))
    # 分页操作
    # photos是一个pagination类型
    photos = Photo.query.paginate(page=page, per_page=3)
 
    user_id = session.get("uid", None)
    user = None
    if user_id:
        user = User.query.get(user_id)
    return render_template("user/myphoto.html", photos=photos, user=user)
 

3. .base.html配置我的相册页面路径

<li><a href="{{ url_for('user.myphoto') }}">我的相册</a></li>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值