"Starting from 0 Tornado site" Home page login and display the latest articles

Source: Internet
Author: User
Tags table definition

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.