1.我的中心的页面布局(html文件及相应的样式文件)css
2.定义视图函数def usercenter(user_id):html
3.向前端页面传递参数前端
4.页面显示相应数据bootstrap
发布的所有问答app
发布的所有评论函数
我的信息布局
5.各个页面连接到我的中心post
@app.route('/usercenter/<user_id>') @loginFirst def usercenter(user_id): user=User.query.filter(User.id==user_id).first() context={ 'username':user.username, 'question':user.question, 'comments':user.comments } return render_template('usercenter.html',**context)
{% extends 'shouye.html' %} {% block title %}我的中心{% endblock %} {% block head %} <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> <link rel="stylesheet" type="text/css" href="../static/css/usercenter.css"> {% endblock %} {% block main %} <div class="page-header"> <h3><span class="glyphicon glyphicon-user" aria-hidden="true"></span>{{ username }}<br> <small>所有问答<span class="s1"></span></small> </h3> <ul class="list-group" style="margin: 10px"> {% for foo in question %} <li class="list-group-item"> <span class="glyphicon glyphicon-heart-empty" aria-hidden="true"></span> <a href="#">{{ foo.author.username }}</a> <span class="s2">{{ foo.create_time }}</span> <p>{{ foo.detail }}</p> </li> {% endfor %} </ul> </div> <div class="page-header"> <h3><span class="glyphicon glyphicon-user" aria-hidden="true"></span>{{ user }}<br> <small>所有评论<span class="s1"></span></small> </h3> <ul class="list-group" style="margin: 10px"> {% for foo in comments %} <li class="list-group-item"> <span class="glyphicon glyphicon-heart-empty" aria-hidden="true"></span> <a href="#">{{ foo.author.username }}</a> <span class="s2">{{ foo.create_time }}</span> <p>{{ foo.detail }}</p> </li> {% endfor %} </ul> </div> <div class="page-header"> <h3><span class="glyphicon glyphicon-user" aria-hidden="true"></span>{{ user }}<br> <small>我的信息<span class="s1"></span></small> </h3> <ul class="list-group" style="margin: 10px"> <li class="list-group-item">用户:{{ username }}</li> <li class="list-group-item">编号:</li> <li class="list-group-item">昵称:</li> </ul> </div> {% endblock %}
{% for foo in ques.comments %} <li class="post_item"> <a href="{{ url_for('usercenter',user_id=foo.author.id) }}" class="light">{{foo.author.username }}</a><br> <p class="post_item">{{ foo.detail }}</p> <span class="foot">发布于 {{ foo.create_time }}</span> </li> <hr> {% endfor %} </ul>