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)

自动化创建tornado项目的更多相关文章

  1. Centos7部署tornado项目

    今天帮一个学生解决tornado的部署问题,在此记录了这其中的过程,其中的tornado项目更换为demo示例. 开发环境: 本地开发环境:Win10 + Python3.5.4 + PyCharm ...

  2. Tornado项目简单创建

    Tornado是使用Python编写的一个强大的.可扩展的Web服务器.它在处理严峻的网络流量时表现得足够强健,但却在创建和编写时有着足够的轻量级,并能够被用在大量的应用和工具中. tornado技术 ...

  3. Java接口自动化测试之Maven项目的创建(一)

    这里使用Idea创建Maven项目, 过程非常简单, 装好JDK和Idea 1. 安装完后,打开Idea, 选择File→New→Project, 如图 2. 选择maven, 点击Next, 如图 ...

  4. tornado项目

    tornado项目之基于领域驱动模型架构设计的京东用户管理后台 本博文将一步步揭秘京东等大型网站的领域驱动模型,致力于让读者完全掌握这种网络架构中的“高富帅”. 一.预备知识: 1.接口: pytho ...

  5. 使用Kotlin创建Android项目

    如果你已经使用过Android Studio和Gradle,那么这一章会比较简单.我不会给出很多细节和截图,因为用户界面和细节可能会一直变化. 我们的应用是由一个简单的天气app组成,正如所使用的Go ...

  6. maven命令行创建web项目报错:java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils

    早上一上班就想新建一个web项目玩玩,没想到一敲命令创建就失败了,真是出师不利.各种折腾无果,当然我也可以用eclipse直接创建的,就是不甘心被这破问题给耍了.刚刚才发现问题原因,这个结果我也是醉了 ...

  7. python+Django实现Nagios自动化添加监控项目

    最近机房刚上了一批机器(有100台左右),需要使用Nagios对这一批机器进行监控.领导要求两天时间完成所有主机的监控.从原来的经验来看,两天时间肯定完成不了.那怎么办?按照之前的想法,肯定是在nag ...

  8. Python+Django+ansible playbook自动化运维项目实战☝☝☝

    Python+Django+ansible playbook自动化运维项目实战☝☝☝  一.入门引导 DevOPSDevOps(英文Development和Operations的组合)是一组过程.方法 ...

  9. 环境配置——tornado项目准备工作

    新建tornado项目后,采用Pycharm作为开发工具,采用Xshell链接Ubuntu模拟服务端方便方便测试.项目编码前进行以下几个方面的配置. 1.Ubuntu配置 1.1安装ssh服务 sud ...

随机推荐

  1. OnSen UI结合AngularJs打造”美团"APP"我的”页面 --Hybrid App

    1.页面效果图: 演示地址:http://www.nxl123.cn/bokeyuan/meiTuanDemo_mine/ 2.核心代码 mine.html: <ons-page id=&quo ...

  2. Lab 6-2

    Analyze the malware found in the file Lab06-02.exe. Questions and Short Answers What operation does ...

  3. p1472 Cow Pedigrees

    用dp[i][j]记录i个点,组成深度恰好为j的方案数.arr[i][j]记录i个点,深度<=j的方案数.那么dp[i][j]只有i为奇数时不为0.而arr[i][j]等于dp[i][j]的前缀 ...

  4. 2.3 UML活动图

    活动图定义 活动图描述了在一个过程中,顺序的/并行的活动及其之间的关系 应用于商业过程.工作流(业务过程).复杂算法的建模 活动图是顶点和弧的集合 活动节点 动作 流 对象值 注解和约束等 活动图基本 ...

  5. 【Java】【5】List随机取值

    //shuffle 打乱顺序 Collections.shuffle(list); //随机抽取1个值 System.out.println(list.get(0)); //随机抽取N个值 Syste ...

  6. 二元谓词中添加const的问题(未解决)

    #include <iostream> using namespace std; #include"set" #include"algorithm" ...

  7. Parse error: syntax error, unexpected end of file in * 的解决办法

    这个原因很简单,就是你的php语法错误. 在你的php代码种出现了<?  ?>  标准的是<?php ?>

  8. oracle中给表和列起别名

    SELECT xxmc,sname as xsxm,sex,phone,address jzdz FROM student s LEFT JOIN xxjbxx x ON x.sid = s.sid ...

  9. [每周一文]week 1

    花开人间四月天 摘自美文网:https://www.lookmw.cn/xinqing/49623.html 赏春   四月芳菲淡淡香,寻花问柳向斜阳.   陌上行人思作客,人间遍地是春情.   文/ ...

  10. axios ajax fetch 区别

    请求方式千千万,axios是一种对ajax的封装,fetch是一种浏览器原生实现的请求方式,跟ajax对等