您现在的位置是: 网站首页 >Flask >Flask搭建微电影视频网站 Flask

【Flask微电影】26.电影会员评论、会员登录日志、会员收藏列表

admin2018年11月12日 21:54 Flask | Html | Python 1542人已围观

Flask搭建微电影视频网站简介 利用Flask搭建微电影视频网站 Github地址:https://github.com/xyliurui/FlaskMovie

### 评论记录 #### 修改 comments评论记录视图 ```python @home.route('/comments/<int:page>/') @user_login_require def comments(page): if not page: page = 1 page_comments =Comment.query.filter_by( user_id=int(session['login_user_id']) ).order_by( Comment.add_time.desc() ).paginate(page=page, per_page=10) return render_template('home/comments.html', page_comments=page_comments) ``` #### 修改usermenu.html评论记录链接 ```html <a id="m-3" href="{{ url_for('home.comments', page=1) }}" class="list-group-item"> <span class="glyphicon glyphicon-comment"></span>&nbsp;评论记录 </a> ``` #### 修改comments.html评论记录列表 ```html <ul class="commentList"> {% for comment in page_comments.items %} <li class="item cl"> <a href="user.html"> <i class="avatar size-L radius"> <img alt="50x50" src="{{ url_for('static', filename='user/' + comment.user.face) }}" class="img-circle" style="border:1px solid #abcdef; width: 50px"> </i> </a> <div class="comment-main"> <header class="comment-header"> <div class="comment-meta"> <a class="comment-author" href="{{ url_for('home.user') }}">{{ comment.user.name }}</a> 评论于 <time title="{{ comment.add_time }}" datetime="{{ comment.add_time }}">{{ comment.add_time }}</time> </div> </header> <div class="comment-body"> <p>{{ comment.content }}!</p> </div> </div> </li> {% endfor %} </ul> {% import 'home/pagination.html' as pg %} {{ pg.render_pagination(page_comments, 'home.comments') }} ``` ![BLOG_20181112_215626_37](/media/blog/images/2018/11/BLOG_20181112_215626_37.png "博客图集BLOG_20181112_215626_37.png") ### 会员登录日志 #### 修改userlog会员登录日志视图 ```python @home.route('/userlog/<int:page>/') @user_login_require def userlog(page=None): """会员登录日志""" if not page: page = 1 page_user_logs = UserLog.query.filter_by( user_id=int(session['login_user_id']) ).order_by( UserLog.add_time.desc() ).paginate(page=page, per_page=10) return render_template('home/userlog.html', page_user_logs=page_user_logs) ``` #### 修改usermenu.html登录日志链接 ```html <a id="m-4" href="{{ url_for('home.userlog', page=1) }}" class="list-group-item"> <span class="glyphicon glyphicon-calendar"></span>&nbsp;登录日志 </a> ``` #### 增加pagination.html分页模板 ```html <div class="col-md-12 text-center" style="margin-top:6px;"> <nav aria-label="Page navigation"> {% macro render_pagination(pagination, url_route) %} <ul class="pagination"> <li> <a href="{{ url_for(url_route, page=1) }}" aria-label="First"> <span aria-hidden="true">首页</span> </a> </li> {% if pagination.has_prev %} <li> <a href="{{ url_for(url_route, page=pagination.prev_num) }}" aria-label="Previous"> <span aria-hidden="true">上一页</span> </a> </li> {% endif %} {%- for page in pagination.iter_pages() %} {% if page %} {% if page != pagination.page %} <li><a href="{{ url_for(url_route, page=page) }}">{{ page }}</a></li> {% else %} <li><a style="background: #0d6aad; color: white">{{ page }}</a></li> {% endif %} {% endif %} {%- endfor %} {% if pagination.has_next %} <li> <a href="{{ url_for(url_route, page=pagination.next_num) }}" aria-label="Next"> <span aria-hidden="true">下一页</span> </a> </li> {% endif %} <li> <a href="{{ url_for(url_route, page=pagination.pages) }}" aria-label="Last"> <span aria-hidden="true">尾页</span> </a> </li> </ul> {% endmacro %} </nav> </div> ``` #### 修改userlog.html登录日志显示模板 ```html <div class="panel-body"> <table class="table table-bordered"> <tr> <td style="width:10%">编号</td> <td style="width:30%">登录时间</td> <td style="width:30%">登录IP</td> <td style="width:30%">登录地址</td> </tr> {% for user_log in page_user_logs.items %} <tr> <td>{{ user_log.id }}</td> <td>{{ user_log.add_time }}</td> <td>{{ user_log.ip }}</td> <td>xxx</td> </tr> {% endfor %} </table> {% import 'home/pagination.html' as pg %} {{ pg.render_pagination(page_user_logs, 'home.userlog') }} </div> ``` ![BLOG_20181112_215638_82](/media/blog/images/2018/11/BLOG_20181112_215638_82.png "博客图集BLOG_20181112_215638_82.png") ### 会员收藏列表 #### 修改moviecollect收藏电影列表视图 ```python @home.route('/moviecollect/<int:page>/') @user_login_require def moviecollect(page): if not page: page = 1 page_moviecollects = MovieCollect.query.filter_by( user_id=int(session['login_user_id']) ).order_by( MovieCollect.add_time.desc() ).paginate(page=page, per_page=10) return render_template('home/moviecollect.html', page_moviecollects=page_moviecollects) ``` #### 修改usermenu.html会员收藏链接 ```html <a id="m-5" href="{{ url_for('home.moviecollect', page=1) }}" class="list-group-item"> <span class="glyphicon glyphicon-heart"></span>&nbsp;收藏电影 </a> ``` #### 修改moviecollect.html会员收藏列表展示 ```html <div class="col-md-12"> {% for moviecollect in page_moviecollects.items %} <div class="media"> <div class="media-left"> <a href="{{ url_for('home.play') }}"> <img class="media-object" src="{{ url_for('static', filename='media/' + moviecollect.movie.logo) }}" alt="{{ moviecollect.movie.title }}" style="width: 120px"> </a> </div> <div class="media-body"> <h4 class="media-heading">{{ moviecollect.movie.title }}<a href="{{ url_for('home.play') }}" class="label label-primary pull-right"><span class="glyphicon glyphicon-play"></span>播放影片</a></h4> {{ moviecollect.movie.info }} </div> </div> {% endfor %} </div> {% import 'home/pagination.html' as pg %} {{ pg.render_pagination(page_moviecollects, 'home.moviecollect') }} ``` ![BLOG_20181112_215653_91](/media/blog/images/2018/11/BLOG_20181112_215653_91.png "博客图集BLOG_20181112_215653_91.png")

很赞哦! (2)

文章交流

  • emoji
0人参与,0条评论

当前用户

未登录,点击   登录

站点信息

  • 建站时间:网站已运行2074天
  • 系统信息:Linux
  • 后台程序:Python: 3.8.10
  • 网站框架:Django: 3.2.6
  • 文章统计:256 篇
  • 文章评论:60 条
  • 腾讯分析网站概况-腾讯分析
  • 百度统计网站概况-百度统计
  • 公众号:微信扫描二维码,关注我们
  • QQ群:QQ加群,下载网站的学习源码
返回
顶部
标题 换行 登录
网站