[Tornado website building from scratch] Overall Design

Source: Internet
Author: User
Tags django tutorial

Tornado is a non-blocking web server and an excellent python web framework. There are a lot of and details about django tutorial on the Internet, and tornado is rarely used, I want to build a small website with this excellent tornado framework step by step in my way from scratch. On the one hand, I want to deepen my understanding, on the other hand, I want to accept suggestions and criticism from everyone, and make more progress ~ I registered a Domain Name: http://www.ustchacker.com, because the server in the school, the Internet can not access, wait until the function is complete and then mounted to the Internet.

I want to build a common website with login, registration, post, comment, group chat, and other functions that can be improved later. The Code is as follows:

import osimport tornado.webimport tornado.ioloopfrom handlers import *handlers=[(r'/',indexHandler),(r'/member',memberHandler),(r'/chat/(\d+)',chatHandler),(r'/register',registerHandler),(r'/logout',logoutHandler),(r'/post',postHandler),(r'/user/(\w+)',userHandler),(r'/blog/(\d+)',blogHandler),(r'/comment',commentHandler),]settings={'static_path':os.path.join(os.path.dirname(__file__),'static'),'template_path':os.path.join(os.path.dirname(__file__),'template'),}app=tornado.web.Application(handlers,**settings)app.listen(8888)tornado.ioloop.IOLoop.instance().start()

/Corresponding to the homepage;/member corresponding to the registered member list;/chat/(\ d +) corresponding to the group chat page, \ d + indicates the number of pages, the reason is that it is better to add more pages to the group chat topic;/register corresponds to registration;/logout corresponds to logout;/post corresponds to post, And/user/(\ w +) corresponds to the homepage of each registered user; /blog/(\ d +) corresponds to each article;/comment is used to post comments.

Create html files in the template directory:

blog.html  index.html  member.html  register.htmlchat.html  main.html   post.html    user.html

A database is also needed. mongodb is very easy to use. However, for the sake of convenience and simplicity, it is okay for the small site to use sqlite3 ~ There are a lot of ORM for databases. Currently, the small site features are simple and I just want to encapsulate it myself.

The frontend frame uses bootstrap, which is in the main model main.html as follows:

<meta charset='utf-8'>

To add bootstrap.css and bootstrap. js, because bootstrap. js depends on jquery, The jquery-2.1.1.js also needs to be added. Later, we will continue to improve and add the small-site function through the following articles, and show the design beauty of tornado in the process.

Reprinted Please note:

Related Article

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.