1.顯示全部評論
{% for foo in ques.comments %}
css
1 <ul class="list-group" style="margin-top: 30px;"> 2 <h1>所有評論</h1> 3 {% for com in comment %} 4 <li class="list-group-item" style="width: 800px"> 5 <a class="wrap-img" href="#" target="_blank"> 6 <img src="http://www.bookmarkye.com/3.jpg" width="50px"> 7 </a> 8 <span class="glyphicon glyphicon-left" aria-hidden="true"></span> 9 <a href="{{ url_for('comment',user_id=com.author.id) }}" 10 target="_blank">{{ com.author.username }}</a> 11 <br> 12 <span class="badge">{{ com.creat_time }}</span> 13 <p style="">{{ com.detail }}</p> 14 </li> 15 {% endfor %} 16 </ul>
2.全部評論排序
uquestion = db.relationship('Question', backref=db.backref('comments', order_by=creat_time.desc))html
1 <ul class="list-group" style=""> 2 <h1>所有問題</h1> 3 {% for foo in questions %} 4 <li class="list-group-item" style="width: 800px"> 5 <a class="wrap-img" href="#" target="_blank"> 6 <img src="http://www.bookmarkye.com/3.jpg" width="50px"> 7 </a> 8 <span class="glyphicon glyphicon-left" aria-hidden="true"></span> 9 <a href="{{ url_for('comment',user_id=foo.author.id) }}" 10 target="_blank">{{ foo.author.username }}</a> 11 <br> 12 <a href="{{ url_for('detail',question_id=foo.id) }}">{{ foo.title }}</a> 13 <span class="badge">{{ foo.creat_time }}</span> 14 <p style="">{{ foo.detail }} 15 </p> 16 </li> 17 {% endfor %} 18 </ul>
3.顯示評論條數
{{ ques.comments|length }}前端
1 <div class="list-group-item" style="margin-top: 30px;width: 800px;"> 2 <h1>名稱:<small>{{ user.username }}</small></h1> 3 <h1>問題數:<small>{{ questions|length }}</small></h1> 4 <h1>評論數:<small>{{ comment|length }}</small></h1> 5 </div>
4.完成我的中心jquery
1.我的中心的頁面佈局(html文件及相應的樣式文件)bootstrap
1 <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css"> 2 <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script> 3 <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
2.定義視圖函數def usercenter(user_id):app
1 # 某用戶發佈過的全部評論 2 @app.route('/comment/<user_id>',methods=['GET','POST']) 3 def comment(user_id): 4 user = User.query.filter(User.id == user_id).first() 5 content = { 6 'comment':user.comment, 7 'questions':user.question, 8 'user2':user 9 } 10 return render_template('comment.html', **content)
3.向前端頁面傳遞參數函數
4.頁面顯示相應數據佈局
發佈的所有問答url
發佈的所有評論spa
我的信息
5.各個頁面連接到我的中心