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

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

  2. 所有评论排序
    uquestion = db.relationship('Question', backref=db.backref('comments', order_by=creat_time.desc))

  3. 显示评论条数
    {{ ques.comments|length }}

  4. 完成个人中心

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

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

3.向前端页面传递参数

4.页面显示相应数据

发布的全部问答

发布的全部评论

个人信息

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

PY:

@app.route('/user/<username_id>')
def yonghu(username_id):
    user = User.query.filter(User.id == username_id).first()
    context = {
        'username':user.username,
        'fabus':user.fabu,
        'comments':user.comments
    }
    return render_template('yonghu.html',**context)

daohang:

{% block switchbody %}
<div class="container">
    <div class="row clearfix">
        <div class="col-md-4 column">
        </div>
        <div class="col-md-4 column">
            {% for foo in wenda  %}

            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">
                        <a href="{{ url_for('detail',question_id=foo.id)}}">标题:{{foo.title }}</a><br>
                    </h3>
                    <a href="{{ url_for('usercenter',user_id=foo.id)}}">{{ foo.author.username }}</a>
                </div>

                <div class="panel-body">
                  <a href="#">内容:{{foo.detail }}</a><br>
                </div>
                <div class="panel-footer">
                     <span class="badge" style="margin-left: 60%">{{foo.creat_time }}时间</span>
                </div>
            </div>
          {% endfor %}
        </div>
        <div class="col-md-4 column">
        </div>
    </div>
</div>



{% endblock %}

</body>
</html>

fabu:

{% extends 'daohang.html' %}
{% block fabu_viewtitle %}发布内容{% endblock %}
{% block fabu_viewhead %}
    <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
{% endblock %}
{% block daohangbody %}
    <div class="col-md-2 column "></div>
    <div class="col-md-8 column ">
        <h2 href="#" class="text-center">{{ fa.title }}</h2>
        <br>
        <p class="text-center">
            <a href="{{ url_for('yonghu',username_id=fa.author_id) }}">
                <small>{{ fa.author.username }}</small>
            </a>&nbsp&nbsp&nbsp
            <span class="pull-center"><small>{{ fa.creat_time }}</small></span>
        </p>
        <hr>
        <p>{{ fa.detail }}</p>
        <hr>

        <form action="{{ url_for('comment') }}" method="post">
            <div class="form-group">
                    <textarea name="pinglun" class="form-control" rows="5" id="pinglun"
                              placeholder="请输入评论"></textarea>
                <input type="hidden" name="fa_id" value="{{ fa.id }}">
            </div>
            <button type="submit" class="btn btn-default">发送</button>
            <br>
            <br>
            <h4>评论:({{ fa.comments|length }})</h4>
            <ul class="list-unstyled">
                {% for foo in fa.comments %}
                    <li class="list-group-item">
                        <a href="{{ url_for('yonghu',username_id=foo.author_id) }}"><span class="glyphicon glyphicon-fire"></span>{{ foo.author.username }}</a>
                        <span class="badge pull-right">{{ foo.creat_time }}</span>
                        <p>{{ foo.detail }}</p>
                        <br>
                    </li>
                {% endfor %}
            </ul>
        </form>
        <br>
        <br>
        <br>

    </div>
    <div class="col-md-2 column "></div>
{% endblock %}

yonghu:

{% extends 'daohang.html' %}
{% block yonghutitle %}用户详情{% endblock %}
{% block yonghuhead %}
    <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
{% endblock %}
{% block daohangbody %}
    <div class="col-md-2 column "></div>
    <div class="col-md-8 column ">
        <h2 href="#" class="text-center">信息</h2>
        <hr>
        <p><span class="glyphicon glyphicon-fire"></span>username</p>
        <br>
        <div class="col-md-6 column s1">
            <h3 class="text-center">发布信息({{ fabus|length }})</h3>
            <ul class="list-unstyled">
                {% for foo in fabus %}
                    <li class="list-group-item">
                        <a href="{{ url_for('yonghu',username_id=foo.author_id) }}"><span class="glyphicon glyphicon-fire"></span>{{ foo.author.username }}</a>
                        <h4 class="text-center"><a href="{{ url_for('fabuview',fabu_id=foo.id) }}">{{ foo.title }}</a>
                        </h4>
                        <span class="badge pull-right">{{ foo.creat_time }}</span>
                        <br>
                        <p>{{ foo.detail }}</p>
                    </li>
                {% endfor %}
            </ul>
        <br>
        <br>
        <br>
        </div>
        <div class="col-md-6 column s1">
            <h3 class="text-center">评论信息({{ comments|length }})</h3>
            <ul class="list-unstyled">
                {% for foo in comments %}
                    <li class="list-group-item">
                        <a href="{{ url_for('yonghu',username_id=foo.author_id) }}"><span class="glyphicon glyphicon-fire"></span>{{ foo.author.username }}</a>
                        <span class="badge pull-right">{{ foo.creat_time }}</span>
                        <p>{{ foo.detail }}</p>
                        <br>
                    </li>
                {% endfor %}
            </ul>
        <br>
        <br>
        <br>
        </div>
    </div>
    <div class="col-md-2 column "></div>
{% endblock %}

 

posted @ 2017-12-13 21:00  003蒋宇翔  阅读(199)  评论(0编辑  收藏  举报