我目前正在将我的数据加载到一个变量中(如下所示为“数据”),然后读取我的模板文件并用“数据”中包含的变量替换 %s。这是我的页面读取、替换、写入然后在本地服务器代码上显示新页面:
def main
contents = makePage('varibletest.html', (data['Address'], data['Admin'], data['City'], data['ContractNo'], data['DealStatus'], data['Dealer'], data['Finance'], data['FinanceNumber'], data['First'], data['Last'], data['Message'], data['Notes'], data['Result'], data['SoldDate'], data['State'], data['Zip'])) # process input into a page
browseLocal(contents, 'Z:/xampp/htdocs/', 'SmartFormTest{}.php'.format((data['ContractNo']))) # display page
def fileToStr(fileName):
"""Return a string containing the contents of the named file."""
fin = open(fileName);
contents = fin.read();
fin.close()
return contents
def makePage(templateFileName, substitutions):
"""Returns a string with substitutions into a format string taken
from the named file. The single parameter substitutions must be in …Run Code Online (Sandbox Code Playgroud)