2017-12-11 4 views
1

竜巻を使用して、私はhtmlファイルを作成し、後で再利用するために保存します。 htmlの中に私の静的なファイルのブートストラップのCSSへの参照が欲しい。静的CSSへのリンク付きの竜巻付き.htmlファイルを作成

マイsimplfied HTMLは次のようになり、Tornado/Python self.render("example.html") ignores CSS

<html> 

<head> 
    <link rel="stylesheet" type="text/css" href="{{static_url('app/content/bootstrap.css')}}" /> 
</head> 

<body> 
{{name}} 
</body> 
</html> 

次私の簡素化の.pyは、次のようになります。

import tornado.template 
loader=tornado.template.Loader(r"C:\templateDirectory") 
output_from_parsed_template= loader.load("template.html").generate(name="John") 

# to save the results 
file = open(r"C:\templateDirectory\result.html","w") 
file.write(output_from_parsed_template) 
file.close() 

しかし、私はメッセージを取得:

NameError: name 'static_url' is not defined

答えて

0

多くをTornadoテンプレートで使用する定義済みの名前のうち、(アプリケーションレベルの設定が必要なため)テンプレートシステム自体ではなく、 static_urlをそのまま使用するには、LoaderとTemplate.generateだけでなく、サーブ全体のスタックが必要です(または、コードを掘り下げて何をしているのかを再構築することができます)。

+0

Ben Darnellに感謝します。 Tornadoでstatic_urlのテンプレートがどのように行われているかの例を教えてください。 – Joris

+0

'tornado/web.py'の' static_url'を検索します。 –

関連する問題