我的问题更多的是礼仪主题,而不是其他任何东西。我正在开发一个相对较小的应用程序,它读取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()