【问题标题】:pass sql result to mako template and show in table将 sql 结果传递给 mako 模板并显示在表格中
【发布时间】:2014-01-16 22:14:54
【问题描述】:

我刚决定学习 Pyramid 并选择 Mako 作为模板语言。我从视图中得到了一个原始 sql 结果列表,如下所示: [{'sample': 'R1_Y200.fq', 'study': 'GaoQiang1'},{'sample': 'R1_Y300.fq', 'study': 'GaoQiang2'},...]

view.py:
@view_config(route_name='example', renderer='example.html')
def templet_test(request):
    ...
    return {'result':search_result}

html:
<html>
...
<table border="1" width="500" align="center" cellpadding="0">
<tr>
  <th >study</th>
  <th >sample</th>

</tr>
% for item in result: 
<tr>
<td valign=top align=center> ${item['study']} </td>
<td valign=top align=center> ${item['sample']} </td>
</tr>
% endfor
</table>
...
</html>

但它没有成功。我收到了这条消息: "内部服务器错误

服务器遇到意外的内部服务器错误

(由服务员生成)"

如何解决?

【问题讨论】:

  • “没有成功”是什么意思?你收到错误信息了吗?它什么也没做?
  • "Internal Server Error 服务器遇到意外的内部服务器错误(由服务员生成)"

标签: html sql mako


【解决方案1】:

真正的异常显示在控制台中 - 它将包含问题的原因。 您可能还希望在金字塔中启用调试工具栏,以便在开发中以更友好的方式处理错误。

另外通过查看您的模板 - 我假设您使用 sqlalchemy 进行数据库交互,您可能希望访问像 item.study 这样的结果行,而不是像 item['study']。

如果没有适当的回溯,我能猜到的就这么多了。

【讨论】:

  • 谢谢,我找到了我的问题。是设置问题~
猜你喜欢
  • 2011-05-08
  • 2021-09-27
  • 2011-12-26
  • 2012-10-14
  • 2021-08-15
  • 1970-01-01
  • 2011-07-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多