@app.route('/usercenter/<user_id>/<tag>')
@loginFirst
def usercenter(user_id,tag):
user=User.query.filter(User.id==user_id).first()
context={
'user':user,
'question':user.question,
'comments':user.comments
}
if tag == '1':
return render_template('usercenter1.html', **context)
elif tag == '2':
return render_template('usercenter2.html', **context)
else:
return render_template('usercenter3.html', **context)
{% extends "base.html" %}
{% block title %}个人中心{% endblock %}
{% block head %}
<style>
.nav nav-tabs li{
list-style: none;
float: left;
margin: 35px;
}
</style>
{% endblock %}
{% block main %}
<h3><span class="glyphicon glyphicon-user" aria-hidden="true"></span>{{ user.username }}</h3>
<ul class="nav nav-tabs">
<li role="presentation"><a href="{{ url_for('usercenter',user_id=user.id,tag=1) }}">全部问答</a></li>
<li role="presentation"><a href="{{ url_for('usercenter',user_id=user.id,tag=2) }}">全部评论</a></li>
<li role="presentation"><a href="{{ url_for('usercenter',user_id=user.id,tag=3) }}">个人信息</a></li>
</ul>
{% block user %}{% endblock %}
{% endblock %}
<a href="{{ url_for('usercenter',user_id=user.id,tag=1) }}">{{user.username }}</a>
<a href="{{ url_for('usercenter',user_id=foo.author_id,tag=1) }}">{{ foo.author.username }}评论:({{ foo.comments|length }})</a><br>
<a href="{{ url_for('usercenter',user_id=foo.author.id,tag=1) }}">{{ foo.author.username }}</a>