@app.route(‘/usercenter/<user_id>/<tag>‘) def usercenter(user_id,tag): user = User.query.filter(User.id == user_id).first() context = { ‘username_id‘: user.id, ‘username‘: user.username, ‘wenda‘: user.wenda, ‘comments‘: user.comment } if tag ==‘1‘: return render_template(‘userquestion.html‘,**context) elif tag ==‘2‘: return render_template(‘usercomment.html‘,**context) else: return render_template(‘usercenter.html‘,**context)
<div class="col-md-4 column"> <div class="panel panel-default"> <div class="panel-heading"> <h3 class="panel-title">标题:{{quest.title }}</h3> <a href="{{ url_for(‘usercenter‘,user_id=quest.author_id,tag=1)}}">作者:{{ quest.author.username}}</a> </div> <div class="panel-body"> <a href="#">内容:{{quest.detail }}</a><br> </div> <div class="panel-footer"> <span class="badge" style="margin-left: 60%">{{quest.creat_time }}发布时间</span> </div> </div> </div> <div class="col-md-4 column"> </div> </div> </div>
<div class="panel panel-default"> <div class="panel-heading"> <h3 class="panel-title"> <a href="{{ url_for(‘detail‘,question_id=foo.id)}}">标题:{{foo.title }}</a><br> </h3> <a href="{{ url_for(‘usercenter‘,user_id=foo.id,tag=1)}}">{{ foo.author.username }}</a> </div> <div class="panel-body"> <a href="#">内容:{{foo.detail }}</a><br> </div> <div class="panel-footer"> <span class="badge" style="margin-left: 60%">{{foo.creat_time }}发布时间</span> </div> </div> {% endfor %} </div> <div class="col-md-4 column"> </div> </div> </div>
<ul class="nav_ul"> <li role="presentation"><a href="{{ url_for(‘usercenter‘,user_id = username_id,tag = 1) }}">question</a> </li> <li role="presentation"><a href="{{ url_for(‘usercenter‘,user_id = username_id,tag = 2) }}">comments</a> </li> <li role="presentation"><a href="{{ url_for(‘usercenter‘,user_id = username_id,tag = 3) }}">information</a> </li> </ul> {% block user %}}{% endblock %} {% endblock %} </html>