求助Django模板中使用list的问题
模板文件:{%fortestcaseinfailed_list%}{{testcase}}{%endfor%}代码:failed_list是从一个html文件中获取到的f...
模板文件:
{% for testcase in failed_list %}
{{testcase}}
{% endfor %}
代码:
failed_list 是从一个html文件中获取到的
from BeautifulSoup import BeautifulSoup
from django.template import Template, Context
import re
import subprocess
testResultFile = '/home1/TestPage.html'
fp = open(testResultFile)
soup = BeautifulSoup(fp)
linkAttrFail = soup.findAll('tr',{'class':"fail"})------->解析TestPage.html获取相关数据
fp = open(testReportTemplate.html')------->使用模板文件
t = Template(fp.read())
c = Context({'failed_list':linkAttrFail })
html = t.render(c)
最终的页面上显示的内容是:
<tr class="fail"> <td class="numeric"> 39 </td> <td class="numeric"> 1 </td> <td class="numeric"> 0 </td> <td class="numeric"> 0 </td> <td> <a href="AtmsAutoTest.McReport.BackgroundScript.McDayReport.ClickChokeDayReport.ClickChokeAreaGroupReport001?pageHistory&resultDate=20130924160259">AtmsAutoTest.McReport.BackgroundScript.McDayReport.ClickChokeDayReport.ClickChokeAreaGroupReport001</a> </td> <td class="numeric"> 79 </td> </tr>
并没有解析到html的标签,这是为什么呢?请各位大侠指点!!
TestPage.html部分内容如下:
<tr class="fail">
<td class="numeric">
39
</td>
<td class="numeric">
1
</td>
<td class="numeric">
0
</td>
<td class="numeric">
0
</td>
<td>
<a href="AtmsAutoTest.McReport.BackgroundScript.McDayReport.ClickChokeDayReport.ClickChokeAreaGroupReport001?pageHistory&resultDate=20130924160259">AtmsAutoTest.McReport.BackgroundScript.McDayReport.ClickChokeDayReport.ClickChokeAreaGroupReport001</a>
</td>
<td class="numeric">
79
</td>
</tr> 展开
{% for testcase in failed_list %}
{{testcase}}
{% endfor %}
代码:
failed_list 是从一个html文件中获取到的
from BeautifulSoup import BeautifulSoup
from django.template import Template, Context
import re
import subprocess
testResultFile = '/home1/TestPage.html'
fp = open(testResultFile)
soup = BeautifulSoup(fp)
linkAttrFail = soup.findAll('tr',{'class':"fail"})------->解析TestPage.html获取相关数据
fp = open(testReportTemplate.html')------->使用模板文件
t = Template(fp.read())
c = Context({'failed_list':linkAttrFail })
html = t.render(c)
最终的页面上显示的内容是:
<tr class="fail"> <td class="numeric"> 39 </td> <td class="numeric"> 1 </td> <td class="numeric"> 0 </td> <td class="numeric"> 0 </td> <td> <a href="AtmsAutoTest.McReport.BackgroundScript.McDayReport.ClickChokeDayReport.ClickChokeAreaGroupReport001?pageHistory&resultDate=20130924160259">AtmsAutoTest.McReport.BackgroundScript.McDayReport.ClickChokeDayReport.ClickChokeAreaGroupReport001</a> </td> <td class="numeric"> 79 </td> </tr>
并没有解析到html的标签,这是为什么呢?请各位大侠指点!!
TestPage.html部分内容如下:
<tr class="fail">
<td class="numeric">
39
</td>
<td class="numeric">
1
</td>
<td class="numeric">
0
</td>
<td class="numeric">
0
</td>
<td>
<a href="AtmsAutoTest.McReport.BackgroundScript.McDayReport.ClickChokeDayReport.ClickChokeAreaGroupReport001?pageHistory&resultDate=20130924160259">AtmsAutoTest.McReport.BackgroundScript.McDayReport.ClickChokeDayReport.ClickChokeAreaGroupReport001</a>
</td>
<td class="numeric">
79
</td>
</tr> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询