我的問題更多的是禮儀主題,而不是其他任何東西。我正在開發一個相對較小的應用程序,它讀取XML數據並寫入Oracle數據庫並輸出到網頁。Django在單獨的文件中的html模板
我在閱讀「Django權威指南:Web開發完成」一書,主要是因爲學習新東西很有趣,我認識到越來越多的工程師需要使用Django體驗。
在這本書中,有一個建議將html模板與其他代碼分開(例如,在它自己的文件夾中的.html文件中)。
這樣做有什麼好處,而不是隻留下嵌入在我的python腳本中的html模板?
我使用的模板是約15行,並使用該數據在生成列表來填充HTML文本:
path_to_be_used = desktop_path + 'XURA_output.html'
f = open(path_to_be_used, 'w')
string = """<html>
<head><title>XURA Messaging</title></head>
<body>
<p>XURA Message contents: the data contained in this page is the Push Notification output retrieved from the XURA server.<br>
Upon arrival this data is subsequently written to the Oracle database.
"""
f.write(string)
line1 = "<p><pre>TAG".ljust(28) + "| " + "TEXT".ljust(40) + " </pre>"
f.write(line1)
for tag in smsreport_list:
tagInfo = tag[0]
textInfo = tag[1]
loop_line = "<pre>" + tagInfo.ljust(20) + "| " + textInfo.ljust(40) + " </pre>"
f.write(loop_line)
line2 = """</p></body>
</html>"""
f.write(line2)
f.close()