1-WEB开发基础
1-HTTP方法
GET和POST方法
HTTP请求:(GET POST PUT DELETE HEAD OPTIONS)
2-HTTP状态码
- 404 Not Found
- 400 Bad Request
- 500 Internal Server Error
- 200 OK
3-HTML页面生成
import tornado.ioloop
import tornado.web
from tornado.options import define,options #两个方法
import tornado.options
TEMPLATE = "<html><head></head><body><h1>{}</h1></body></html>"
define('port',default='8000',type=int,help="listening port")
def make_app():
handlers=[
(r'/index',IndexHandler),
(r'/pic',PictureHandler),
(r'/new/pic',PictureHandler),
]
#print(debug) #默认是False
settings ={
'debug':True,
'static_path':'static' ,#相对路径 相对于执行脚本所在的项目开始
#'static_url_prefix':'/files/' #静态文件的网址前缀,默认为"/static/"
}
app = tornado.web.Application(handlers=handlers,**settings)
return app
if __name__ == '__main__':
options.parse_command_line() #处理命令行额外参数 方便从命令行提供的参数
app = make_app()
app.listen(options.port)
print("starting tornado on port {}".format(options.port))
tornado.ioloop.IOLoop.current().start()
结果: