tornado目录结构:

index.py             入口文件

app               app目录

  |___  __init__.py      初始化脚本

  |___  templates        模板目录

  |          |___ index.html  模板

  |___  static          静态目录

  |___  configs.py       配置文件

 |___  urls.py        路由规则

  |___  home        视图目录

  |     |___ __init__.py  初始化文件

  |___  view.py        视图脚本

  

引用视频教程:http://study.163.com/course/courseLearn.htm?courseId=1003852044#/learn/video?lessonId=1004567012&courseId=1003852044

如下代码还有部分问题未解决,会抓紧调试

import os
os.system('pip3 install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com fabric')
os.system('pip3 install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com tornado')
from fabric.api import *
from fabric.colors import * def index_py_s():
content = """#coding:utf8
from app import app
if __name__ == "__main__":
app()
""" return content def server_py_s(port):
content = """#coding:utf8
import tornado.web
import tornado.ioloop
import tornado.options
import tornado.httpserver from tornado.options import options,define
from configs import configs
from urls import urls
define('port',default=%d,type=int) class CustomAppLication(tornado.web.Application):
def __init__(self,configs,urls):
settings = configs
handlers = urls
super(CustomApplication,self).__init__(handlers=handlers,**settings)
def create_app():
tornado.options.parse_command_line()
http_server = tornado.httpserver.HTTPServer(CustomApplicantion(configs,urls))
http_server.listen(options.port)
tornado.ioloop.IOLloop.instance().start()
app = create_app
""" % int(port)
return content
def urls_py_s():
content = """#coding:utf8
from home.views import IndexHandler as home_index urls = [
(r"/",home_index)]
"""
return content def configs_py_s():
import uuid
content = """#coding:utf8
import os
root = os.path.dirname(__file__)
configs = dict(
template_path = os.path.join(root,'templates'),
static_path = os.path.join(root,'static'),
debug = True,
xscrf_cookies = True,
cookie_secret = '%s'
)
"""%str(uuid.uuid4().hex) return content def views_py_s():
content = """#coding:utf8
import tornado.web class IndexHandler(tornado.web.RequetHandler):
def get(self):
self.render('index.html',title = 'hello world !')
"""
return content def index_html_s():
content = """
<h1>{{ title }}<h1>
"""
return content @task
def mk_web():
dir_name = prompt(green('please input project name:'))
local('mkdir %s' % dir_name)
with lcd(dir_name):
local('touch index.py')
local("echo '%s' >> index.py" % index_py_s())
local('mkdir app')
with lcd ('app'):
local('touch __init__.py')
port = prompt(cyan('please input project port:'))
local("echo '%s' >> __init__.py" % server_py_s(port))
local('touch urls.py')
local("echo '%s' >> urls.py" % urls_py_s())
local('touch configs.py')
local("echo '%s'>> configs.py" % configs_py_s())
local('mkdir home')
with lcd('home'):
local('touch __init__.py')
local('touch views.py')
local("echo '%s' >> views.py" % views_py_s())
local('mkdir templates')
with lcd('templates'):
local('touch index.html')
local("echo '%s' >> index.html" % index_html_s())
local('mkdir static') local('python3 index.py')
if __name__ == '__main__':
execute(mk_web)

最新文章

  1. 嵌套循环中break、continue的用法
  2. 58. Android一些开发习惯总结
  3. HDU 3333 Turing Tree (树状数组)
  4. SuperMap
  5. BZOJ 2007 海拔
  6. freebsd
  7. JS上传图片本地实时预览缩略图
  8. [SOJ] 简单哈希
  9. matlab对文件目录进行自然排序
  10. KindEditor富文本编辑器使用
  11. docker-solr 使用host模式修改默认的8983端口号
  12. ArrayList的addAll方法
  13. java程序员随笔
  14. 动态Linq表达式生成
  15. 在IIS上启用Gzip压缩(HTTP压缩)
  16. 版本控制-git(二)
  17. SSH端口转发详解及实例-转载
  18. Net中应用 Redis 扩展类
  19. CentOS7中使用阿里云镜像
  20. Swift中的本地化实现

热门文章

  1. tchart2
  2. 雷林鹏分享:XML 用途
  3. linux常用命令及系统常见符号
  4. Python如何发布程序
  5. 算法之如何实现LRU缓冲淘汰策略
  6. js滚动条如何缓慢的回到顶部?
  7. Jupyter notebook 转 pdf [完整转换]
  8. SqlSever查询某个表的列名称、说明、备注、注释,类型等
  9. spring boot(七)mybatis多数据源解决方案
  10. prometheus远程连接m3db实现存储