Log home can only be placed in it, here the beauty, the <form> use bootstrap Form-inline modified class, for example in the following way:
The foreground code is as follows:
{%extends ' main.html '%} {%block Header%}<ul class= ' nav nav-pills ' ><li><a href= '/' class= ' h4 text-primary ' > Home </a>< /li><li><a href= '/member ' class= ' h4 text-primary ' > member </a></li><li><a href= '/ Chat/1 ' class= ' h4 text-primary ' > Group chat </a></li>{%if not cookiename%}<form action= '/' method= ' post ' class= ' form-inline ' ><div class= ' form-group ' ><label class= ' sr-only ' >username</label>< Input type= ' text ' name= ' username ' class= ' form-control ' placeholder= ' username '/></div><div class= ' Form-group ' ><label class= ' sr-only ' > Password </label><input type= ' password ' name= ' password ' class= ' Form-control ' placeholder= ' password '/></div><button type= ' submit ' class= ' btn btn-success ' > Login </button ><a href= '/register ' > No account, please click on the brochure </a></form>{%else%}<li><a href= '/user/{{cookiename} ' class= ' h4 text-primary ' > welcome: {{Cookiename}}</a></li><li><a href= '/logout ' class= ' h4 text-primary ' > Logout </a></li>{%end%}</ul>{%end%}{%block content%}<ul> {%for i in Blogs%}<li><a href= '/user/{{i[1]}} ' class= ' text-success h4 ' > ' {{i[1]}} ' </a><a href= '/ Blog/{{i[0]}} ' class= ' text-primary h3 ' >{{i[2]}}</a></p><p class= ' text-muted h6 ' >{{i[3]}}</ p></li><br/>{%end%}</ul>{%end%}
Background code such as the following:
Class Indexhandler (Tornado.web.RequestHandler):d EF Get (self): Name=self.get_cookie (' Hackername ') blogs=showallblog () Self.render (' index.html ', cookiename=name,blogs=blogs) def post (self): name=self.get_argument (' username ') pw= Self.get_argument (' password ') Res=check (NAME,PW) if res: #password正确self. Set_cookie (' Hackername ', name) Else: # Password error passself.redirect ('/')
The Showallblog function is an article that displays all the users who have published, such as the following:
Def showallblog (): C.execute (' Select id,name,title,time from blog ') Tmp=c.fetchall () return tmp[::-1]
Sorted according to publication time. is the reverse output. The Database Blog table definition is as follows:
CREATE TABLE Blog (ID integer primary key,name text,title text,blog text,time text);
So that each person publishes the latest articles will be displayed on the home page, login successful after the home Display demo sample such as the following:
Click Username to access the user's homepage.
Reprint Please specify: Transfer from http://blog.csdn.net/littlethunder/article/details/25559095
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
"Starting from 0 Tornado site" Home page login and display the latest articles