标签:href orm pre gif rip tool 列表 span trap
py文件:
@app.route(‘/‘) def moban(): context = { ‘wenda‘: Wenda.query.order_by(‘creat_time‘).all() } return render_template(‘moban.html‘,**context)
html文件:
<ul class="news-list"> {% for foo in wenda %} <li class="list-group-item"> <span class="glyphicon glyphicon-leaf" aria-hidden="true"></span> <a href="#">{{ foo.author.username}}</a> <br> <a href="{{ url_for(‘detail‘,wenda_id= foo.id) }}">{{ foo.title }}</a> <br> <span class="badge" >{{ foo.creat_time }}</span> <p style=" padding: 0px; line-height: 1.8; color: rgb(128, 0, 0);">">{{ foo.detail }}</p> </li> {% endfor %} </ul>
2、完成问答详情页布局:
1 {% extends ‘moban.html‘ %} 2 {% block title %}详情界面{% endblock %} 3 {% block head %} 4 <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css"> 5 <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script> 6 <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script> 7 {% endblock %} 8 {% block body %} 9 <div class="col-md-2 column "></div> 10 <div class="col-md-8 column "> 11 <ul class="list-unstyled"> 12 <li> 13 <h2 href="#" class="text-center">{{ www.title }}</h2> 14 <br> 15 <p class="text-center"> 16 <a href="#"> 17 <small>{{ www.author.username }}</small> 18 </a>    19 <span class="pull-center"><small>{{ www.creat_time }}</small></span> 20 </p> 21 <p>{{ www.detail }}</p> 22 <form> 23 <div class="form-group"> 24 <textarea name="comment" class="form-control" rows="6" id="comment" 25 placeholder="请输入评论"></textarea> 26 </div> 27 <button type="submit" class="btn btn-default">发送</button> 28 </form> 29 </li> 30 </ul> 31 </div> 32 <div class="col-md-2 column "></div> 33 {% endblock %}
3、在首页点击问答标题,链接到相应详情页。
1 @app.route(‘/detail?<wenda_id>‘) 2 def detail(wenda_id): 3 wen = Wenda.query.filter(Wenda.id == wenda_id).first() 4 return render_template(‘detail.html‘,www=wen)
标签:href orm pre gif rip tool 列表 span trap
原文地址:http://www.cnblogs.com/018linbin/p/7955668.html