• 从首页问答标题到问答详情页


      1. 主PY文件写视图函数,带id参数。 
        @app.route('/detail/<question_id>')
        def detail(question_id):
            quest = 
            return render_template('detail.html', ques = quest) 
      2. 首页标题的标签做带参数的链接。
              {{ url_for('detail',question_id = foo.id) }}

      3. 在详情页将数据的显示在恰当的位置。 
        {{ ques.title}}
        {{ ques.id  }}{{  ques.creat_time }}
        {{ ques.author.username }} 
        {{ ques.detail }}
      4. 建立评论的对象关系映射:

        class Comment(db.Model):
            __tablename__='comment'

      5.  尝试实现发布评论。

    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'))
        detail=db.Column(db.Text,nullable=False)
        creatTime=db.Column(db.DateTime,default=datetime.now)
        question=db.relationship('Question',backref=db.backref('comments',order_by=creatTime.desc))
        author=db.relationship('User',backref=db.backref('comments'))
    <div class="detail">
        <div class="detail_left">
    
        <h2>{{ question.title }}</h2>
        <a class="username">{{ question.author.username }}</a>
        <span class="badge">{{ question.creatTime }}</span>
        <hr>
        <a style="white-space: pre-wrap"  >{{ question.detail }}</a>
        <hr>
        <form action="{{ url_for('comment') }}" method="post">
        <textarea name='detail' class="form-control" rows="6" id="Detail"></textarea>
        <br><button class="btn-default">发布</button>
         </form>
        <p>评论:({{ question.comments|length }})</p>
        <ul class="comment">
            {% for foo in question.comments %}
            <span class="icon" aria-hidden="true"></span>
            <a href="#" class="name">{{ foo.author.username }}</a>
             <span class="badge2">{{ foo.creatTime }}</span>
               <br>
            <p class="neirong">{{ foo.detail }}</p>
    
            {% endfor %}
        </ul>
    
    
    </div>
    </div>
    </body>
  • 相关阅读:
    项目中的注意事项
    复合查询
    树型控件的处理(完整版)
    图的存储结构(邻接矩阵)
    图的定义与术语2 数据结构和算法55
    图的存储结构(邻接矩阵)
    赫夫曼编码 数据结构和算法52
    赫夫曼编码 数据结构和算法52
    图的存储结构(邻接矩阵)
    图的定义与术语 数据结构和算法54
  • 原文地址:https://www.cnblogs.com/0055sun/p/8000511.html
Copyright © 2020-2023  润新知