标签:out temp style att turn route ima primary table
@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‘
尝试实现发布评论。
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)
creatTime=db.Column(db.DateTime,default=datetime.now)
question=db.relationship(‘Question‘,backref=db.backref(‘comments‘,order_by=creatTime.desc))
author=db.relationship(‘User‘,backref=db.backref(‘comments‘))
<div class="detail"> <div class="detail_left"> <h2>{{ question.title }}</h2> <a class="username">{{ question.author.username }}</a> <span class="badge">{{ question.creatTime }}</span> <hr> <a style="white-space: pre-wrap" >{{ question.detail }}</a> <hr> <form action="{{ url_for(‘comment‘) }}" method="post"> <textarea name=‘detail‘ class="form-control" rows="6" id="Detail"></textarea> <br><button class="btn-default">发布</button> </form> <p>评论:({{ question.comments|length }})</p> <ul class="comment"> {% for foo in question.comments %} <span class="icon" aria-hidden="true"></span> <a href="#" class="name">{{ foo.author.username }}</a> <span class="badge2">{{ foo.creatTime }}</span> <br> <p class="neirong">{{ foo.detail }}</p> {% endfor %} </ul> </div> </div> </body>
标签:out temp style att turn route ima primary table
原文地址:http://www.cnblogs.com/0055sun/p/8000511.html