{% for each in comments %} <li class="list-group-item" > <a class="author" href="">{{ each.author.username }}</a> <br> <br> <span >{{ each.create_time }}</span> <p class="abstract">{{ each.detail }}</p> </li> {% endfor %}
question = db.relationship('Question', backref=db.backref('comment', order_by=create_time.desc()))
<h2>評論:({{ ques.comment|length }})</h2>
1.我的中心的頁面佈局(html文件及相應的樣式文件)html
2.定義視圖函數def usercenter(user_id):前端
3.向前端頁面傳遞參數app
4.頁面顯示相應數據函數
發佈的所有問答佈局
發佈的所有評論spa
我的信息code
5.各個頁面連接到我的中心orm
@app.route('/userCenter/<user_id>', methods=['GET']) def userCenter(user_id): user = User.query.filter(User.id == user_id).first() context = { 'username': user.username, 'questions': user.question, 'comments': user.comment } return render_template('userCenter.html', **context)
{% extends 'fumoban.html' %} {% block title %}我的中心 {% endblock%} {% block main%} <div class="page-header"> <h3><span class="glyphicon glyphicon-user" aria-hidden="true"></span> {{username}} <br> <small>detail comment<span class="badge"></span> </small></h3> <ul class="list-group" style=""> {% for foo in user.question %} <li class="list-group-item"> <span class="glyphicon glyphicon-heart-empty" aria-hidden="true"></span> <a href="#">{{foo.author.username }}</a> <span class="badge">{{foo.creat_time}}</span> <p style="">{{foo.detail}}</p> </li> {% endfor %} </ul> </div> <div class="page-header"> <h3><span class="glyphicon glyphicon-user" aria-hidden="true"></span> {{user}} <br> <small>personal information<span class="badge"></span> </small></h3> <ul class="list-group" style=""> {% for foo in user.comments %} <li class="list-group-item"> <span class="glyphicon glyphicon-heart-empty" aria-hidden="true"></span> <a href="#">{{foo.author.username }}</a> <span class="badge">{{foo.creat_time}}</span> <p style="">{{foo.detail}}</p> </li> {% endfor %} </ul> </div> <div class="page-header"> <h3><span class="glyphicon glyphicon-user" aria-hidden="true"></span> {{user}} <br> <small>personal information<span class="badge"></span> </small></h3> <ul class="list-group" style=""> <li class="list-group-item">user:{{username}}</li> <li class="list-group-item">time:</li> <li class="list-group-item">nick:</li> <li class="list-group-item">context:</li> </ul> </div> {% endblock %}