• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
陈华斐
博客园    首页    新随笔    联系   管理    订阅  订阅
完成个人中心—导航标签
    1. 个人中心—视图函数带标签页面参数tag
      @app.route('/usercenter/<user_id>/<tag>')
      def usercenter(user_id, tag):
         if tag == ‘1':
             return render_template('usercenter1.html', **context)

    2. 个人中心—导航标签链接增加tag参数
      <li role=“presentation”><a href=“{{ url_for(‘usercenter’,user_id = user.id,tag = ‘1’) }}">全部问答</a></li>
    3. 个人中心—有链接到个人中心页面的url增加tag参数
      u <a href="{{ url_for('usercenter',user_id = session.get('userid'), tag=1) }}">{{ session.get('user') }}</a>

py:

@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)

daohang.html:

<a href="{{ url_for('usercenter',user_id=session.get('user'),tag=1)}}">{{ session.get('user') }}</a>

detail.html:

<a href="{{ url_for('usercenter',user_id=foo.author.id,tag=2) }}">{{ foo.author.username }}</a>

 

posted on 2017-12-15 10:49  026陈华斐  阅读(114)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3