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


    显示所有评论
    {% for foo in ques.comments %}

    <h4>评论:({{ quest.comment|length }})</h4>
         {% for foo in comments %}
                <div class="list-group">
                     <a href="" class="list-group-item active">作者:{{ foo.author.username}}</a>
    
                    <div class="list-group-item">
                        <a href="" class="list-group-item-heading">
    
                        </a>
                        <p class="list-group-item-text">
                            {{foo.detail}}
                        </p>
                    </div>
                    <div class="list-group-item">
                         <span class="badge">发布时间:{{foo.creat_time}}</span> 发布时间
                    </div>
            </div>
                 {% endfor %}
      1. 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'))
            creat_time = db.Column(db.DateTime, default=datetime.now)
            detail = db.Column(db.Text, nullable=False)
            question = db.relationship('Ques', backref=db.backref('comment', order_by=creat_time.desc))
            author = db.relationship('User', backref=db.backref('comment'))
        1. 显示评论条数
          {{ ques.comments|length }}

        2. 完成个人中心

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

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

        3.向前端页面传递参数

        4.页面显示相应数据

        发布的全部问答

        发布的全部评论

        个人信息

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

        {% 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=" 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=" 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 %}
      2. 所有评论排序
        uquestion = db.relationship('Question', backref=db.backref('comments', order_by=creat_time.desc))
        @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)
  • 相关阅读:
    svn使用
    canvas入门-3渐变方法
    canvas入门-2路径、文字
    canvas入门-1三种填充方式、渐变、模式
    jquery extend的使用
    angular入门-ngOptions
    jquery-EasyUI---panel面板的用法
    jquery-EasyUI---tooltip提示框的使用
    jquery-EasyUI---progressbar进度条的的使用
    jquery-EasyUI---searchbox搜索框的用法
  • 原文地址:https://www.cnblogs.com/cch-1007/p/8035018.html
Copyright © 2020-2023  润新知