当前位置: 首页 > news >正文

评论列表显示及排序,个人中心显示

 


  1. 显示所有评论
    {% for foo in ques.comments %}
     <h4>评论:({{ ques.comments|length }})</h4>
    
            <ul class="list-unstyled">
                {% for foo in comments %}
                    <li class="list-group-item">
                        <a href="{{  url_for('usercenter',user_id = foo.author.id) }}">{{ foo.author.username }}</a>
                        <span class="badge pull-right">{{ foo.create_time }}</span>
                        <p>{{ foo.detail }}</p>
                        <br>
                    </li>
                {% endfor %}
            </ul>

     

  2. 所有评论排序
    uquestion = db.relationship('Question', backref=db.backref('comments', order_by=creat_time.desc))
    class Comment(db.Model):
        __tablename__ = 'comment'
        id = db.Column(db.Integer, primary_key=True, autoincrement=True)
        author_id = db.Column(db.Integer, db.ForeignKey('user.id'))
        question_id = db.Column(db.Integer, db.ForeignKey('question.id'))
        create_time = db.Column(db.DateTime, default=datetime.now)
        detail = db.Column(db.Text, nullable=False)
        question = db.relationship('Question',backref=db.backref('comments',order_by=create_time.desc))
        author = db.relationship('User',backref=db.backref('comments'))
    
    db.create_all()

     

  3. 显示评论条数
    {{ ques.comments|length }}
            <h4>评论:({{ ques.comments|length }})</h4>

     

  4. 完成个人中心
    {% extends 'userr.html' %}
    {% block title %}
        个人中心
    {% endblock %}
    
    {% block ab %}
    
        <div class="container">
            <div class="row clearfix">
                <div class="col-md-2 column">
                </div>
                <div class="col-md-8 column">
    
                    <ul class="list-group">
                        <li class="list-group-item" >
                            <h3 align="center">个人信息</h3>
                            <img style="width: 30px" src="{{ url_for('static',filename='css/touxiang.jpg') }}" alt="64">
                            <a href="#">用户名:{{ username }}</a><br>
                            <a>文章篇数:{{ questions|length }}</a>
                            <p style="margin-left: 25%"></p><br>
                        </li>
                    </ul>
                    <ul class="list-group">
                        {% for foo in questions %}
                            <li class="list-group-item" >
                                <img style="width: 30px" src="{{ url_for('static',filename='css/touxiang.jpg') }}"
                                     alt="64">
                                <a href="#">{{ username }}</a><br>
                                <a href="{{ url_for('detail',question_id=foo.id) }}">问题:{{ foo.title }}</a><br>
                                <p style="align-content: center">{{ foo.detail }}</p>
                                <span>评论数: ({{ foo.comments|length }})</span>
                                <span class="badge" style="margin-left: 60%">{{ foo.create_time }}</span>
                                <p style="margin-left: 25%"></p><br>
                            </li>
                        {% endfor %}
                    </ul>
    
                    <ul class="list-group">
                        {% for foo in comments %}
                            <li class="list-group-item">
                                <span class="badge pull-right">{{ foo.create_time }}</span>
                                <p>文章标题:{{ foo.question.title }}</p>
                                <p>评论内容:{{ foo.detail }}</p>
                                <span class="glyphicon glyphicon-user"></span>
                                <small><a>{{ foo.author.username }}</a></small>
                                <br>
                            </li>
                        {% endfor %}
                    </ul>
    
    
                </div>
                <div class="col-md-2 column">
                </div>
            </div>
        </div>
    {% endblock %}

     

1.个人中心的页面布局(html文件及相应的样式文件)

2.定义视图函数def usercenter(user_id):

@app.route('/usercenter/<user_id>')
@log
def usercenter(user_id):
    user = User.query.filter(User.id == user_id).first()
    context ={
        'username':user.username,
        'questions':user.question,
        'comments':user.comments
    }
    return render_template('usercenter.html',**context)

 

3.向前端页面传递参数

4.页面显示相应数据

发布的全部问答

发布的全部评论

个人信息

5.各个页面链接到个人中心

 

 

转载于:https://www.cnblogs.com/zhuyinyinyin/p/8034862.html

相关文章:

  • jQuery效果之jQuery Color animation 色彩动画扩展
  • Qt---自定义界面之QStyle
  • 再学习之Spring(面向切面编程).
  • java:解决eclipse配置Tomcat时找不到server选项
  • Qt532.QSettings_默认分隔符
  • python 高阶函数三 filter()和sorted()
  • bzoj1036[ZJOI2008]树的统计Count 树链剖分+线段树
  • 自然语言处理入门学习(一)
  • 文件和目录权限chmod 更改所有者和所属组chown umask 隐藏权限lsattr/chattr
  • 面向对象java知识汇总题
  • PAT 1023.组个最小数
  • mongodb for windows安装
  • 【比赛】NOIP2017 宝藏
  • gdb调试多线程程序总结
  • Excel2016通过宏生成拼音码
  • Android单元测试 - 几个重要问题
  • emacs初体验
  • js对象的深浅拷贝
  • linux安装openssl、swoole等扩展的具体步骤
  • RxJS: 简单入门
  • Stream流与Lambda表达式(三) 静态工厂类Collectors
  • uni-app项目数字滚动
  • Vue2 SSR 的优化之旅
  • webpack+react项目初体验——记录我的webpack环境配置
  • Zepto.js源码学习之二
  • 好的网址,关于.net 4.0 ,vs 2010
  • 基于Dubbo+ZooKeeper的分布式服务的实现
  • 力扣(LeetCode)56
  • 嵌入式文件系统
  • 微信小程序开发问题汇总
  • 一些css基础学习笔记
  • 源码安装memcached和php memcache扩展
  • ​水经微图Web1.5.0版即将上线
  • # 学号 2017-2018-20172309 《程序设计与数据结构》实验三报告
  • $.ajax()参数及用法
  • (12)目标检测_SSD基于pytorch搭建代码
  • (3)(3.5) 遥测无线电区域条例
  • (4) PIVOT 和 UPIVOT 的使用
  • (Demo分享)利用原生JavaScript-随机数-实现做一个烟花案例
  • (附源码)ssm教材管理系统 毕业设计 011229
  • (四)库存超卖案例实战——优化redis分布式锁
  • (转)Sublime Text3配置Lua运行环境
  • (转载)CentOS查看系统信息|CentOS查看命令
  • *++p:p先自+,然后*p,最终为3 ++*p:先*p,即arr[0]=1,然后再++,最终为2 *p++:值为arr[0],即1,该语句执行完毕后,p指向arr[1]
  • .[hudsonL@cock.li].mkp勒索病毒数据怎么处理|数据解密恢复
  • .helper勒索病毒的最新威胁:如何恢复您的数据?
  • .NET CLR Hosting 简介
  • .NET gRPC 和RESTful简单对比
  • .NET MAUI学习笔记——2.构建第一个程序_初级篇
  • .NET 中的轻量级线程安全
  • .net6+aspose.words导出word并转pdf
  • .net网站发布-允许更新此预编译站点
  • .NET委托:一个关于C#的睡前故事
  • /var/log/cvslog 太大
  • @Transactional注解下,循环取序列的值,但得到的值都相同的问题