Show All comments
{% for Foo in ques.comments%}
<Div> <h4>Comment: ({{sen.comments|length}})</h4>{% for Foo in comment%}<ulstyle= "padding-left:0px;margin-bottom:0px;"> <Liclass= "List-group-item"style= "width:900px"> <ahref= "{{url_for (' usercenter ', User_id=foo.author.id)}}">{{Foo.author.username}}</a> <spanclass= "badge">Comment Time: {{foo.creat_time}}</span> <P>{{Foo.detail}}</P> </Li> </ul>{% endfor%}</Div>
All comments Sorted
Uquestion = db.relationship (' Question ', backref=db.backref (' comments ', order_by=creat_time.desc))
Class Comment (db. Model): __tablename__ = ' comment ' id = db. Column (db. Integer, Primary_key=true, autoincrement=true) author_id = db. Column (db. Integer, Db. ForeignKey (' user.id ')) sent_id = db. Column (db. Integer, Db. ForeignKey (' sent.id ')) creat_time = db. Column (db. DateTime, default=datetime.now) detail = db. Column (db. TEXT, nullable=false) sent = Db.relationship (' Sent ', Backref=db.backref (' comments ', order_by=creat_time.desc)) author = db.relationship (' User ', backref=db.backref (' comments '))
Show number of comment bars
{{Ques.comments|length}
< h4 > Comments: ({{sen.comments|length}})</h4>
Page layouts for personal centers (HTML files and corresponding style files)
. The page displays the corresponding data
All questions and Answers released
All comments Posted
Personal information
Html
{% extends ' index.html '%}<title>{% block title%} Personal Center {% Endblock%}</title>{% block head%}<Linkrel= "stylesheet"type= "Text/css"href= "{{url_for (' static ', filename= ' Css/geren.css ')}}">{% Endblock%}{#<Linkrel= "stylesheet"href=".. /static/css/geren.css ">#} {% block body%}<Divclass= "All Have-img"> <Div>{% for Foo in username%}<h4>User name: {{foo.author.username}}<BR> <Small>All questions</Small> </h4> <ulstyle= "padding-left:0px;margin-bottom:0px;"> <Liclass= "List-group-item"style= "width:900px"> <ahref="">{{Foo.author.username}}</a> <spanclass= "badge">Comment Time: {{foo.creat_time}}</span> <P>{{Foo.detail}}</P> </Li> </ul> </Div> <HR> <Div>{% for Foo in comment%}<h4>User name: {{foo.author.username}}<BR> <Small>All reviews</Small> </h4> <ulstyle= "padding-left:0px;margin-bottom:0px;"> <binclass= "List-group-item"style= "width:900px"> <ahref="#">{{Foo.author.username}}</a> <spanclass= "badge">Comment Time: {{foo.creat_time}}</span> <P>{{Foo.detail}}</P> </Li> </ul> </Div> <HR> <Div> <h4>{{User}}<BR> <Small>User profile</Small> </h4> <ulstyle= "padding-left:0px;margin-bottom:0px;"> <Liclass= "List-group-item"style= "width:900px">User: {{username}}</Li> <Liclass= "List-group-item"style= "width:900px">Number:</Li> <binclass= "List-group-item"style= "width:900px">Nickname:</Li> </ul> </Div></Div>{% Endblock%}
As1
. all { margin-left:300px; Margin-right:auto; width:300px;}. have-img { list-style-type:none;}. List-group-item { position:relative; Display:block; padding:10px 15px; Margin-bottom: -1px; Background-color: #fff; border:1px solid #ddd;}. badge { display:inline-block; min-width:10px; PADDING:3PX 7px; font-size:12px; font-weight:700; line-height:1; Color: #fff; Text-align:center; White-space:nowrap; Vertical-align:middle; Background-color: #777; border-radius:10px; margin-left:650px;} HR { width:930px; Color: #fcf3f3;}
. Defining View Functions def usercenter (USER_ID)
@app. Route ('/usercenter/<user_id>') @loginFirstdef usercenter (user_id): User=user.query.filter (user.id==user_id). First () context={ ' username ': user.username, ' sent ': User.sent, ' comments ': user.comments } return render_template (' geren.html ', **context)
3. Passing parameters to the front-end page
<type= "hidden" name= "sent_id" ID = "sent_id" value= "{{sen.id}}">
5. Each page links to a personal center
#首页用户名链接到个人中心<aclass= "nickname"Target= "_blank"href= "{{url_for (' usercenter ', user_id=foo.author_id)}}">{{Foo.author.username}}</a>#详情用户名连接到个人中心<ahref= "{{url_for (' usercenter ', User_id=foo.author.id)}}">{{Foo.author.username}}</a>
Comments list display and sort, personal center display