<h4>評論:({{ ques.comments|length }})</h4> <ul class="list-unstyled"> {% for foo in comments %} <li class="list-group-item"> <a href="{{ url_for('usercenter',user_id = foo.author.id) }}">{{ foo.author.username }}</a> <span class="badge pull-right">{{ foo.create_time }}</span> <p>{{ foo.detail }}</p> <br> </li> {% endfor %} </ul>
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'))
create_time = db.Column(db.DateTime, default=datetime.now)
detail = db.Column(db.Text, nullable=False)
question = db.relationship('Question',backref=db.backref('comments',order_by=create_time.desc))
author = db.relationship('User',backref=db.backref('comments'))
db.create_all()
<h4>評論:({{ ques.comments|length }})</h4>
{% extends 'userr.html' %} {% block title %} 我的中心 {% endblock %} {% block ab %} <div class="container"> <div class="row clearfix"> <div class="col-md-2 column"> </div> <div class="col-md-8 column"> <ul class="list-group"> <li class="list-group-item" > <h3 align="center">我的信息</h3> <img style="width: 30px" src="{{ url_for('static',filename='css/touxiang.jpg') }}" alt="64"> <a href="#">用戶名:{{ username }}</a><br> <a>文章篇數:{{ questions|length }}</a> <p style="margin-left: 25%"></p><br> </li> </ul> <ul class="list-group"> {% for foo in questions %} <li class="list-group-item" > <img style="width: 30px" src="{{ url_for('static',filename='css/touxiang.jpg') }}" alt="64"> <a href="#">{{ username }}</a><br> <a href="{{ url_for('detail',question_id=foo.id) }}">問題:{{ foo.title }}</a><br> <p style="align-content: center">{{ foo.detail }}</p> <span>評論數: ({{ foo.comments|length }})</span> <span class="badge" style="margin-left: 60%">{{ foo.create_time }}</span> <p style="margin-left: 25%"></p><br> </li> {% endfor %} </ul> <ul class="list-group"> {% for foo in comments %} <li class="list-group-item"> <span class="badge pull-right">{{ foo.create_time }}</span> <p>文章標題:{{ foo.question.title }}</p> <p>評論內容:{{ foo.detail }}</p> <span class="glyphicon glyphicon-user"></span> <small><a>{{ foo.author.username }}</a></small> <br> </li> {% endfor %} </ul> </div> <div class="col-md-2 column"> </div> </div> </div> {% endblock %}
1.我的中心的頁面佈局(html文件及相應的樣式文件)css
2.定義視圖函數def usercenter(user_id):html
@app.route('/usercenter/<user_id>') @log def usercenter(user_id): user = User.query.filter(User.id == user_id).first() context ={ 'username':user.username, 'questions':user.question, 'comments':user.comments } return render_template('usercenter.html',**context)
3.向前端頁面傳遞參數前端
4.頁面顯示相應數據app
發佈的所有問答ide
發佈的所有評論函數
我的信息佈局
5.各個頁面連接到我的中心url