1. 程式人生 > >完成評論功能

完成評論功能

png bsp use nbsp sub head pre 完成 評論

    1. 定義評論的視圖函數
      @app.route(‘/comment/‘,methods=[‘POST‘])
      def comment():
      讀取前端頁面數據,保存到數據庫中
    2. 用<input type="hidden" 方法獲取前端的"question_id"
    3. 顯示評論次數
    4. 要求評論前登錄
    5. 嘗試實現詳情頁面下的評論列表顯示

python:

技術分享圖片

html:

{% extends‘base.html‘ %}
{% block title %}
    問答詳情
{% endblock %}
{% block head %}
    <link rel="stylesheet" href="{{ url_for(‘static‘,filename=‘css/detail.css‘) }}"
type="text/css"> {% endblock %} {% block main %} <body id="myBody"> <div class="total"> <div class="page-header" style="text-align: left"> <h3 style="font-family: 楷體;color: #c879ff;">{{ ques.title }}<br> <small>作者:{{ ques.author.username }}&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
<span class="badge" style="border: hidden;background-color: darkgray;border-radius: 10px">{{ ques.creat_time }}</span> </small> </h3> <hr> </div> <p class="lead">
{{ ques.detail }}</p> <hr> <form method="post" action="{{ url_for(‘comment‘) }}"> <div class="form-group" style="text-align: left"> <textarea name="new_comment" class="form-control" rows="3" placeholder="Write your comment" id="new_comment"></textarea> <input name="question_id" type="hidden" value="{{ ques.id }}"/> </div> <button type="submit" class="btn btn-default" style="border-radius: inherit;font-family: 幼圓">發送</button> </form> <h3 style="text-align: left">評論:({{ ques.comments|length }})</h3> <ul class="list-group"> {% for foo in ques.comments %} <li class="list-group-item"> <span class="glyphicon glyphicon-left" aria-hidden="true"></span> <br> <a href="#" style="font-family: 楷體;color: #c879ff;text-align: left">作者:{{ foo.author.username }}</a>&nbsp&nbsp&nbsp&nbsp&nbsp <span class="badge" style="font-family: 楷體;color: #c879ff;text-align: right">評論時間:{{ foo.creat_time }}</span> <p style="text-align: left">{{ foo.detail }} </p> </li> {% endfor %} </ul> </div> </body> </html> {% endblock %}

技術分享圖片

技術分享圖片

完成評論功能