完成个人中心—导航标签
个人中心—视图函数带标签页面参数tag
@app.route('/usercenter/<user_id>/<tag>')
def usercenter(user_id, tag):
if tag == ‘1':
return render_template('usercenter1.html', **context)
@app.route('/username/<user_id>/<tag>') @loginFirst def usercenter(user_id, tag): user = User.query.filter(User.id == user_id).first() context = { 'user': user, 'post': user.post, '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)
2、个人中心—导航标签链接增加tag参数
<li role=“presentation”><a href=“{{ url_for(‘usercenter’,user_id = user.id,tag = ‘1’) }}">全部问答</a></li>
{% extends 'base.html' %} {% block title %}个人中心{% endblock %} {% block head %} <style> .nav_ul li { list-style: none; float: left; margin: 10px; } </style> {% endblock %} {% block main %} <ul class="nav_ul"> <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 %}
3、个人中心—有链接到个人中心页面的url增加tag参数
u <a href="{{ url_for('usercenter',user_id = session.get('userid'), tag=1) }}">{{ session.get('user') }}</a>
{% extends 'base.html' %} {% block title %}{% endblock %} {% block main %} <p>{{ user }}发布问答</p> <ul class="list-group"> {% for foo in post %} <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',post_id=foo.id)}}">{{foo.title}}</a> <a href="{{ url_for('usercenter',user_id=foo.author_id,tag=1)}}">{{ foo.author.username }}<br>{{ foo.author.username }}<br>评论:({{ foo.comments|length }})</a><br> <span class="badge">{{ foo.creat_time }}</span> <p style="">{{ foo.detail }}</p> </li> {% endfor %} </ul> {% endblock %}