从首页问答标题到问答详情页
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>首页 {% block logintitle %}{% endblock %} {% block registertitle %}{% endblock %} </title> <nav style="background-color: white"> <ul class="nav nav-tabs"> <li><a href="{{ url_for('lx') }}">首页</a></li> {% if username %} <li><a href="#">{{ username }}</a></li> <li><a href="{{ url_for('logout')}}">注销</a></li> {% else %} <li><a href="{{ url_for('login') }}">登录</a></li> <li><a href="{{ url_for('regist') }}">注册</a></li> {% endif %} <li><a href="{{ url_for('fabu') }}">发布</a></li> <li><input type="text" class="form-control" style="width: 200px"></li> <button type="button" class="btn btn-default">搜索</button> </ul> </nav> {% block loginhead %}{% endblock %} {% block registerhead %}{% endblock %} </head> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> <link type="text/css" rel="stylesheet" href="{{ url_for('static',filename='css/webb.css') }}"> <body class="body"> <h1 align="center">欢迎进入我的网站</h1> {% block body %} <div class="container"> <div class="row clearfix"> <div class="col-md-2 column"> </div> <div class="col-md-8 column"> {% for foo in question %} <div class="list-group"> <a href="" class="list-group-item active">作者:{{ foo.author_id}}</a> <div class="list-group-item"> <a href="{{ url_for('detail',question_id=foo.id)}}" class="list-group-item-heading"> {{ foo.title}} </a> <p class="list-group-item-text"> {{foo.detail}} </p> </div> <div class="list-group-item"> <span class="badge">发布时间:{{foo.creat_time}}</span> 发布时间 </div> </div> {% endfor %} <div class="col-md-2 column"> </div> </div> </div> {% endblock %} <footer class="foot"> <div><a href="#"> 联系我们</a> · <a href="#"> 加入我们</a> · <a href="#"> 品牌与徽标 </a> · <a href="#">帮助中心</a> · <a href="#">合作伙伴</a> </div> <div>©2015-2017 广州商学院信息技术与工程学院 / 粤ICP备278953737号-5 / 粤公网安备2015060050046号 / Smrz 粤公网安备201506050046号 / Wxb 举报电话:020-15533935928 </div> </footer> </body> </html>
{% extends 'lx3.html' %} {% block registertitle %} 内容{% endblock %} {% block registerhead %} <script type="text/javascript" src="../static/js/js.js"></script>{% endblock %} <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> <link rel="stylesheet" type="text/css" href="../static/css/webb.css"> <base href="www.gzcc.cn" target="_blank"> <body id="myBody"> {% block body %} <div class="panel panel-default"> <ul><li>作者:{{ quest.author_id}}</li><li>time:{{ quest.creat_time}}</li></ul> <div class="panel-heading"> <h3 class="panel-title"> {{ quest.title}} </h3> </div> <div class="panel-body"> {{ quest.detail}} </div> </div> <div> <form action="{{ url_for('')}}"method="post"> <textarea name="detail" id="detail" cols="30" rows="10"></textarea> <button type="submit">发布</button> </form> </div> </body> {% endblock %} </html>
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')) creat_time = db.Column(db.DateTime, default=datetime.now) detail = db.Column(db.Text, nullable=False) question = db.relationship('Ques', backref=db.backref('comment')) author = db.relationship('User', backref=db.backref('comment')) db.create_all() @app.route('/detail/<question_id>', methods=['GET', 'POST']) def detail(question_id): quest = Ques.query.filter(Ques.id == question_id).first() return render_template('detail.html', quest=quest)