个人中心—视图函数带标签页面参数tag
@app.route(‘/usercenter/<user_id>/<tag>‘)
def usercenter(user_id, tag):
if tag == ‘1‘:
return render_template(‘usercenter1.html‘, **context)
@app.route(‘/usercenter/<user_id>/<tag>‘) @loginFirst def usercenter(user_id, tag): user = User.query.filter(User.id == user_id).first() context = { ‘username‘: user.username, ‘sent‘: user.sent, ‘comments‘: user.comments, ‘user‘: user } if tag == ‘wenda‘: return render_template(‘wenda.html‘, **context) elif tag == ‘pinlun‘: return render_template(‘pinlun.html‘, **context) else: return render_template(‘GRZX.html‘, **context)
- 个人中心—导航标签链接增加tag参数
<li role=“presentation”><a href=“{{ url_for(‘usercenter’,user_id = user.id,tag = ‘1’) }}">全部问答</a></li>
<!DOCTYPE html> <html lang="en"> <head> {% extends ‘index.html‘ %} <meta charset="UTF-8"> <title>{% block title %} 个人 {% endblock %}</title> {% block head %} <link rel="stylesheet" type="text/css" href="{{ url_for(‘static‘,filename=‘css/user.css‘) }}"> {% endblock %} </head> <body> {% block body %} <div class="all"> <ul class="nav_ul"> <li role="presentation" class="active"><a href="{{ url_for(‘usercenter‘ ,user_id=user.id,tag=‘wenda‘) }}">问答</a></li> <li role="presentation"><a href="{{ url_for(‘usercenter‘ ,user_id=user.id,tag=‘pinlun‘) }}">评论</a></li> <li role="presentation"><a href="{{ url_for(‘usercenter‘ ,user_id=user.id,tag=‘geren‘) }}">个人信息</a></li> </ul> </div> {% block user %}{% endblock %} {% endblock %} </body> </html>
个人中心—有链接到个人中心页面的url增加tag参数
u <a href="{{ url_for(‘usercenter‘,user_id = session.get(‘userid‘), tag=1) }}">{{ session.get(‘user‘) }}</a>
个人中心—有链接到个人中心页面的url增加tag参数
u <a href="{{ url_for(‘usercenter‘,user_id = session.get(‘userid‘), tag=1) }}">{{ session.get(‘user‘) }}</a>
#首页 <a class="nickname" href="{{ url_for(‘usercenter‘,user_id=foo.author_id,tag=‘wenda‘)}}">{{ foo.author.username }}</a> #详情页: <a href="{{ url_for(‘usercenter‘,user_id=foo.author.id,tag=‘wenda‘) }}">{{ foo.author.username }}</a> #导航 <li><a href="{{ url_for(‘usercenter‘,user_id=user.id,tag=‘wenda‘) }}">{{ usern }}</a></li>