1. 程式人生 > >python全棧系列之---tornado初識(1)

python全棧系列之---tornado初識(1)

start 存在 IT span imp 基礎 復用 -- 不常用

import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        # self.write("Hello World")
        # 默認當前路徑尋找
        self.render("s1.html")

    def post(self, *args, **kwargs):
        self.write("Hello World")

st ={
    "template_path": "template
",#模板路徑配置 "static_path":commons, #js css等靜態文件路徑配置 無論這裏配置了什麽路徑,在靜態文件中使用都是用static "static_url_prefix":/ss/, #在static_path必須存在的基礎上 類似於對其取了一個別名 #若是沒有static_url_prefix,則在靜態文件中的資源獲取為static/s1.css #當存在static_url_prefix時,(前提已經存在static_path),這時具體路徑程序已經獲取,你只需要在資源前面加上這個前綴,不需要自己去寫具體url #
就是可以看做為static_path起了一個別名 #static_url_prefix了解即可,不常用 } #路由映射 匹配執行,否則404 application = tornado.web.Application([ ("/index",MainHandler), ],**st) if __name__=="__main__": application.listen(8080) #io多路復用 tornado.ioloop.IOLoop.instance().start()

python全棧系列之---tornado初識(1)