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

來源:互聯網
上載者:User

標籤:ati   pat   *args   name   瞭解   模板   rgs   pytho   htm   

import tornado.ioloopimport tornado.webclass 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瞭解即可,不常用}#路由映射   匹配執行,否則404application = tornado.web.Application([    ("/index",MainHandler),],**st)if __name__=="__main__":    application.listen(8080)    #io多工    tornado.ioloop.IOLoop.instance().start()

 

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.