Flask开发微电影网站(四) (3)

由于每个用户的电影评论数可能有很多,这许多的评论不可能在一个页面上全部显示完成,所以要进行分页,默认显示第一页的评论内容

@home.route("/comments/<int:page>/") def comments(page=None): if page is None: page = 1 page_data = Comment.query.join(Movie).join(User).filter( Movie.id == Comment.movie_id, User.id == session["user_id"] ).order_by(Comment.id).paginate(page=page, per_page=10) return render_template("home/comments.html", page_data=page_data) 4.2 定义用户查看自己的评论的前端页面代码 {% extends "home/home.html" %} {% import "ui/home_page.html" as pg %} {% block css %} <style> .col-lg-1, .col-lg-10, .col-lg-11, .col-lg-12, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8, .col-lg-9, .col-md-1, .col-md-10, .col-md-11, .col-md-12, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8, .col-md-9, .col-sm-1, .col-sm-10, .col-sm-11, .col-sm-12, .col-sm-2, .col-sm-3, .col-sm-4, .col-sm-5, .col-sm-6, .col-sm-7, .col-sm-8, .col-sm-9, .col-xs-1, .col-xs-10, .col-xs-11, .col-xs-12, .col-xs-2, .col-xs-3, .col-xs-4, .col-xs-5, .col-xs-6, .col-xs-7, .col-xs-8, .col-xs-9 { padding-right: 3px; padding-left: 3px; } </style> {% endblock %} {% block content %} {% include "home/menu.html" %} <div> <div> <div> <h3><span></span>&nbsp;评论记录</h3> </div> <div> <ul> {% for v in page_data.items %} <li> <a href="http://www.likecs.com/user.html"> <i> <img alt="50x50" src="{{ url_for('static',filename='uploads/users' + v.user.face) }}"> </i> </a> <div> <header> <div> <a href="http://www.likecs.com/user.html">{{ v.user.name }}</a> 评论于 <time title="2016-12-07 09:12:51" datetime="2016-12-07 09:12:51">{{ v.addtime }}</time> </div> </header> <div> <p>{{ v.content | safe }}</p> </div> </div> </li> {% endfor %} </ul> <div> {{ pg.page(page_data,'home.comments') }} </div> </div> </div> </div> {% endblock %} {% block js %} <script> $(document).ready(function () { $("#m-3").addClass("active"); }); </script> {% endblock %} 5. 定义用户登录日志部分代码 5.1 定义用户查看自己的登录日志的视图函数

每个用户登录的次数可以有很多,所以要进行分页,默认显示第一页的登录日志

@home.route("/loginlog/<int:page>/", methods=['GET']) def loginlog(page=None): if page is None: page = 1 page_data = Userlog.query.filter_by(user_id=int(session.get("user_id"))).order_by( Userlog.id ).paginate(page=page, per_page=10) return render_template("home/loginlog.html", page_data=page_data) 5.2 定义用户查看自己的登录日志的前端页面代码 {% extends "home/home.html" %} {% import "ui/home_page.html" as pg %} {% block css %} <style> .col-lg-1, .col-lg-10, .col-lg-11, .col-lg-12, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8, .col-lg-9, .col-md-1, .col-md-10, .col-md-11, .col-md-12, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8, .col-md-9, .col-sm-1, .col-sm-10, .col-sm-11, .col-sm-12, .col-sm-2, .col-sm-3, .col-sm-4, .col-sm-5, .col-sm-6, .col-sm-7, .col-sm-8, .col-sm-9, .col-xs-1, .col-xs-10, .col-xs-11, .col-xs-12, .col-xs-2, .col-xs-3, .col-xs-4, .col-xs-5, .col-xs-6, .col-xs-7, .col-xs-8, .col-xs-9 { padding-right: 3px; padding-left: 3px; } </style> {% endblock %} {% block content %} {% include "home/menu.html" %} <div> <div> <div> <h3><span></span>&nbsp;登录日志</h3> </div> <div> <table> <tr> <td>编号</td> <td>登录时间</td> <td>登录IP</td> </tr> {% for v in page_data.items %} <tr> <td>{{ v.id }}</td> <td>{{ v.addtime }}</td> <td>{{ v.ip }}</td> </tr> {% endfor %} </table> <div> {{ pg.page(page_data,'home.loginlog') }} </div> </div> </div> </div> {% endblock %} {% block js %} <script> $(document).ready(function () { $("#m-4").addClass("active"); }); </script> {% endblock %} 6. 定义用户查看自己的电影收藏的部分的代码 6.1 定义用户查看自己收藏的电影的视图函数

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpzygy.html