yishhaoo

个人中心—视图函数带标签页面参数tag
@app.route(\'/usercenter/<user_id>/<tag>\')
def usercenter(user_id, tag):
   if tag == ‘1\':
       return render_template(\'usercenter1.html\', **context)

py文件:

@app.route(\'/user/<user_id>/<tag>\')
@loginFirst
def user(user_id, tag):
    user = User.query.filter(User.id == user_id).first()
    context = {
        \'user\': user,
        \'username\': user.username,
        \'questions\': user.question,  # 用反向定义的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)


#

 

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

有链接到个人中心页面的url增加tag参数html文件:

<span><img src="../static/img/touxiang.jpg " width="30px" alt=""></span><a href="{{ url_for(\'user\',user_id = foo.author_id,tag = 1) }}">{{ foo.author.username }}</a>
 <a href="{{ url_for(\'user\',user_id = foo.author.id,tag = 1) }}">{{ foo.author.username }}</a>
    <li><a href="{{ url_for(\'user\',user_id =session.get(\'id\'),tag = 1) }}">{{ sessusername }}</a></li>

运行截图:

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-10-23
  • 2021-04-17
  • 2021-06-27
  • 2021-05-22
  • 2021-11-12
  • 2022-02-08
猜你喜欢
  • 2021-05-28
  • 2022-01-23
  • 2021-06-09
  • 2022-12-23
  • 2022-01-15
  • 2022-01-13
  • 2022-12-23
相关资源
相似解决方案