パスにいくつかの jinja テンプレート ファイルがあり、それらをレンダリングしてファイルに書き込みたいのですが、私の問題は出力ファイル名です。
jinja テンプレートで関数を定義してテンプレート出力ファイル名を返して準備し、それを Python コードから呼び出してその値を取得することは可能ですか?
これは私のコードです:
#in here inputPath is jinja templates path
for root, dirs, files in os.walk(inputPath):
for file in files:
fPath = root[len(inputPath) + 1:]
newPath = (fPath + "/" if fPath else '') + file
template = env.get_template(newPath)
oPath = os.path.join(outputPath, fPath)
try:
os.makedirs(oPath)
except:
pass
oPath=os.path.join(oPath,file)
with codecs.open(oPath,'w', "utf-8") as f:
f.write(template.render(projectname=projectName, mainxmlpath=mainXamlPath))
このコードの出力ファイル名は、正確に jinja テンプレート ファイル名です。