标签:mode 参数 pull lock primary datetime filter user list
@app.route(‘/detail/<question_id>‘)
def detail(question_id):
quest =
return render_template(‘detail.html‘, ques = quest)
{{ ques.title}}
{{ ques.id }}{{ ques.creat_time }}
{{ ques.author.username }}
{{ ques.detail }}
建立评论的对象关系映射:
class Comment(db.Model):
__tablename__=‘comment‘
尝试实现发布评论。
1.
@app.route(‘/detail/<question_id>‘) def detail(question_id): fa = Question.query.filter(Question.id == question_id).first() return render_template(‘detail.html‘, fa=fa)
23.
<ul class="list-unstyled"> {% for foo in question %} <li class="list-group-item-success"> <a href="#">{{ foo.author.username }}</a> <h4 class="text-center"><a href="{{ url_for(‘detail‘,question_id=foo.id) }}">{{ foo.title }}</a> </h4> <span class="badge pull-right">{{ foo.creat_time }}</span> <br> <p>{{ foo.detail }}</p> </li> {% endfor %} </ul>
4.
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) crea_time = db.Column(db.DateTime, default=datetime.now) author = db.relationship(‘User‘, backref=db.backref(‘comment‘)) question = db.relationship(‘Question‘, backref=db.backref(‘comment‘))
标签:mode 参数 pull lock primary datetime filter user list
原文地址:http://www.cnblogs.com/qq724852210/p/8000596.html