zoukankan      html  css  js  c++  java
  • 评论列表显示及排序,个人中心显示

        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.各个页面链接到个人中心

    index.html

    {% extends'base.html' %}
        {% block title %}
        首页
        {% endblock %}
    {% block head %}
    
        <script src="{{url_for('static',filename='js/base.js') }}" type="text/javascript"></script>
        <link href="{{ url_for('static' ,filename='css/base.css') }}"  rel="stylesheet" type="text/css">
        {% endblock %}
        {% block main %}
    
        {% for foo in question %}
    <body id="myBody">
            <div id="gufeng">
            <a href="{{ url_for('usercenter',user_id = foo.author_id) }}">{{ foo.author.username }}评论({{ foo.comments|length }})</a>
           <ul class="list" >
                 <li>用户名:{{ foo.author.username }}</li>
              <a href="{{ url_for("detail",question_id=foo.id) }}">标题:{{ foo.title }}</a>
               <li class="">问题:{{ foo.detail }}</li>
               <li class="">时间:{{ foo.time }}</li>
           </ul>
            </div>
        {% endfor %}
        <footer>
            <div class="footer_box">
                Copyright@2017-2027 个人版权,版权所有 作者:JZX telephone:0000-1234567 mobile phone:11111111111
            </div>
        </footer>
    {% endblock %}

     detail.html

    % extends "base.html" %}
    {% block title%}详细内容{% endblock %}
    
    {% block main %}
    <body bgcolor="#ffd700">
        <div class="GuFeng">
            <a href="{{ url_for('usercenter',user_id = foo.author.id) }}">{{ foo.author.username }}</a>
            {   <form action="{{ url_for('/detail/<question_id>') }}" method="post">}
          <h2>标题:{{ ques.title }}</h2><br>
          <h3>用户名:{{ ques.author.username }}</h3><br>
          <h3> 发布时间:{{ ques.create_time }}</h3>
          <p>内容:{{ ques.detail }}</p>
            <hr>
            <textarea class='comment'rows="10"id="detail"name="detail"></textarea>
            <br><input  type="submit" value="发布"style="100px;height:50px;font-size:50px">
            <input name="question_id" type="hidden" value="{{ ques.id }}"/>
            <p>评论:</p>
            <table border=5 style="background: gold"width="50">
                <tr><td>评论内容</td></tr>
                <tr><td>评论内容</td> </tr>
                <tr><td>评论内容</td></tr>
                </tr>
            </table>
        </div>
    </body>
    {% endblock %}

     usercenter.html

    {% extends'base.html' %}
    {% block title %}
        个人中心
    {% endblock %}
    {% block head %}
        <link rel="stylesheet" href="{{ url_for('static',filename='css/user.css')}}" type="text/css">
    {% endblock %}
    {% block main %}
    <div class="all question">
         <h2><a href="{{ url_for('usercenter',user_id=user.id) }}"> {{ user.username }}</a>全部问答</h2>
          <ul class="wenda" style=" auto">
              {% for foo in user.question %}
                 <li class="wenti">
                     <a href="#">{{ foo.author.username }} </a>
                    <span>{{ foo.creat_time }}</span><br>
                    <a class="title" href="{{ url_for('detail',question_id=foo.id) }}">{{ foo.title }}</a><br>
                    <p>{{ foo.detail }}</p>
                 </li>
               {% endfor %}
          </ul>
    </div>
    
    <div class="all detail" >
        <h2><a href="{{ url_for('usercenter',user_id=user.id) }}"> {{ user.username }}</a>全部评论</h2>
        <ul class="pinglun" style=" auto">
            {% for foo in user.comments %}
            <li class="comment">
                 <a href="#">{{ foo.author.username }} </a>
                    <span>{{ foo.creat_time }}</span><br>
                    <p>{{ foo.detail }}</p>
            </li>
            {% endfor %}
        </ul>
    </div>
    
    <div class="usercenter">
         <h2><a href="{{ url_for('usercenter',user_id=user.id) }}"> {{ user.username }}</a>个人中心</h2>
         <ul class="yonghu" style=" auto">
                <li><p>用户:{{ user.username }}</p></li>
                <li><p>编号:{{ user.id }}</p></li>
                <li><p>昵称:{{ user.nickname}}</p></li>
                <li><p>文章篇数:{{ user.question|length }}</p></li>
         </ul>
    </div>
    {% endblock %}

     py

    @app.route('/usercenter/<user_id>')
    @loginFirst
    def usercenter(user_id):
        user=User.query.filter(User.id==user_id).first()
        context={
            'user':user
        }
        return render_template('center.html',**context)
  • 相关阅读:
    MOSS中的User的Title, LoginName, DisplayName, SID之间的关系
    如何在Network Monitor中高亮间隔时间过长的帧?
    SharePoint服务器如果需要安装杀毒软件, 需要注意什么?
    如何查看SQL Profiler? 如何查看SQL死锁?
    什么是Telnet
    The name or security ID (SID) of the domain specified is inconsistent with the trust information for that domain.
    Windows SharePoint Service 3.0的某个Web Application无搜索结果
    网络连接不上, 有TCP错误, 如果操作系统是Windows Server 2003, 请尝试一下这里
    在WinDBG中查看内存的命令
    The virtual machine could not be started because the hypervisor is not running
  • 原文地址:https://www.cnblogs.com/gdlyzx/p/8034271.html
Copyright © 2011-2022 走看看