bootstrap + tornado

来源:互联网 发布:淘宝网怎么登录不了 编辑:程序博客网 时间:2024/05/27 00:44

1、下载bootstrap压缩包

wget http://d.bootcss.com/bootstrap-3.3.5-dist.zip

2、解压

unzip bootstrap-3.3.5-dist.zip

3、vi t.py

#coding:utf-8
import os,sys
import tornado.ioloop
import tornado.web
from tornado.escape import json_encode


class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.render(
            "index.html",
            apis = apis
        )


application = tornado.web.Application(
    handlers = [
      (r'/',MainHandler)
    ],
    template_path = os.path.join(os.path.dirname(__file__),'templates'),
    static_path = os.path.join(os.path.dirname(__file__),'bootstrap-3.3.5-dist'),
    debug = True
)




if __name__ == "__main__":
    application.listen(8000)
    tornado.ioloop.IOLoop.instance().start()


vi templates/main.html

<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
    <title>Bootstrap 101 Template</title>


    <!-- Bootstrap -->
    <link href="{{ static_url("css/bootstrap.min.css") }}" rel="stylesheet">


    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="//cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="//cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
    <div class="container">
    {% block body %}{% end %}
    </div>
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="//cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="{{ static_url("js/bootstrap.min.js") }}"></script>
    <script type="text/javascript">
    {% block script %}{% end %}
    </script>
  </body>
</html>


vi templates/index.html

{% extends "main.html" %}
{% block body %}

hello world

{% end %}

{% block script %}

{% end %}


0 0