完成个人中心—导航标签2

    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>
    4. @app.route('/usercenter/<user_id>/<tag>')
      def usercenter(user_id,tag):
          user = User.query.filter(User.id == user_id).first()
          context = {
              'usern': user.id,
              'username': user.username,
              'fankui':user.fankui,
              'comment':user.comment
          }
          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)

       

    5. {% extends'danghangye.html' %}
      {% block title %}个人中心{% endblock %}
      {% block head %}
      <style>
              .nav_ul li {
                  list-style:none;
                  float:left;
                  margin:10px;
                  border-bottom:outset;
      
              }
          </style>
      
      {% endblock %}
      
      
      
      {% block main %}
      
          <ul class="nav_ul">
              <li role="presentation" ><a href="{{url_for('usercenter',user_id = usern,tag = 1)}}">fankui</a></li>
              <li role="presentation"><a href="{{url_for('usercenter',user_id = usern,tag = 2)}}">comment</a></li>
              <li role="presentation"><a href="{{url_for('usercenter',user_id = usern,tag = 3)}}">person</a></li>
      
      
          </ul>
      
      {% block usercenter %}{% endblock %}
      
      
      {% endblock %}
        <!DOCTYPE html>
              <html lang="en">
              <head>
              {% block head %}{% endblock %}
                  <meta charset="UTF-8">
                  <title>{% block title %}{% endblock %}首页</title>
                  <nav style="background-color: slategray">
                      <img src="http://cdn2.jianshu.io/assets/web/logo-58fd04f6f0de908401aa561cda6a0688.png" width="40px">
                  <link rel="stylesheet" href="{{url_for('static',filename='css/loginMy.css')}}">
                  <script type="text/javascript" src="../static/js/switch.js"></script>
                      <img  src="{{url_for('static',filename='image/yezi.jpg')}}" alt="wo" width="50px">
                     {% if usernamedd %}
      
                     <a href="{{url_for('usercenter',user_id = session.get('id'),tag = 1)}}"> {{usernamedd}}</a>
      
                       <a href="{{url_for('logout')}}">注销</a>
                      <a href="{{url_for('edit')}}">编辑</a>
      
                      {% else %}
                       <a href="{{url_for('login')}}">login</a>
                       <a href="{{url_for('register')}}">register</a>
      
                      {% endif %}
      
      
      
               <a href="{{url_for('fankui')}}">fankui</a>
              <a href="{{url_for('danghangye')}}">首页</a>
      
      
      
      
                      <img id="myOnOff" onclick="mySwitch()" src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1509532539555&di=5c7e5df90fa122e5a6dcae2de5fb45d5&imgtype=0&src=http%3A%2F%2Fwww.jbhdq.com%2Fuploadfile%2F2016%2F0617%2F20160617103213932.jpg"
                   width="40px">
              <input class="input_control" type="text" placeholder="" name="" size="10" ><button>搜索</button>
                 </nav>
      
      
      
               <!--<script>-->
                      <!--function mySwitch() {-->
                          <!--var oBody= document.getElementById("myBody");-->
                          <!--var oOnoff=document.getElementById("myOnOff");-->
                          <!--if(oOnoff.src.match("b9999_")){-->
                              <!--oOnoff.src="https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1509520370&di=f7ae57dab90eab30c78e8f4733607b02&src=http://pic29.photophoto.cn/20131121/0017029581107509_b.jpg";-->
                              <!--oBody.style.background="black";-->
                              <!--oBody.style.color="yellow";-->
                          <!--}else{oOnoff.src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1509532539555&di=5c7e5df90fa122e5a6dcae2de5fb45d5&imgtype=0&src=http%3A%2F%2Fwww.jbhdq.com%2Fuploadfile%2F2016%2F0617%2F20160617103213932.jpg";-->
                              <!--oBody.style.background="white";-->
                              <!--oBody.style.color="black";-->
                          <!--}-->
                      <!--}-->
               <!--</script>-->
      
              </head>
      
              <body id="myBody">
              {% block main %}
      
               <P align="center" style="background-color:rgba(255,255,0,0.25)">{{username}}请登录</P>
                <ur class="sss" style="background-color:rgba(255,255,0,0.25)">
                    {% for foo in fankui %}
                       <li class="list">
                       <span class="glyphicon" aria-hidden="true"></span>
                       <a href="{{url_for('usercenter',user_id = foo.author_id,tag = 1)}}">{{foo.author.username}}评论({{foo.comment|length}})</a>
                       <br>
                       <a href="{{url_for('详情页',fankui_id = foo.id )}}">{{foo.biaoti}}</a>
                       <span class="badge">{{foo.creat_time}} </span>
                       <p>{{foo.questionDetail}}</p>
      
      
                      </li>
                    {% endfor %}
      
                </ur>
      
      
      
               {% endblock %}
              </body>
              </html>

       

posted on 2017-12-15 09:51  201506050009曹艺健  阅读(96)  评论(0编辑  收藏  举报