2013-03-13 34 views
4

我是Python和Tornado Web框架的初學者。當我在書裏學習模板部分「Introduction to Tornado」,一條線搞糊塗了:static_url調用Tornado

<link rel="stylesheet" href="{{ static_url("style.css") }}"> 

應用怎樣才能知道在哪裏調用函數static_url當沒有進口到命名空間庫?我在Tornado的web模塊中發現了static_url(),但我無法弄清楚該模塊文件中如何成功調用該函數?

回答

5

RequestHandler類有一個方法get_template_namespace(),記錄here。如果您點擊源鏈接,則會看到how it creates a dictionary,其中'static_url'設置爲self.static_url

+0

謝謝!我會研究這一點。 – Kuan 2013-03-15 20:40:53