Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django月度网格/表格_Django_Django Templates - Fatal编程技术网

Django月度网格/表格

Django月度网格/表格,django,django-templates,Django,Django Templates,我有一个月回报率的股票投资组合。目前,报税表存储在数据库中,作为每个月的第一天和每年的第一天。 因此,2016年1月1日-5% 2016年2月1日-3% 在Django模板中显示此内容的最佳方式是什么? 我希望每年都有一个单独的行,列是日期,因此: Jan Feb Mar Apr.... 2014 2015 2016 什么是将月度回报置于正确位置的最佳方法 谢谢你的帮助 我不知道这是否是最好的方法,但我最终使用了一个元组列表来实现这一点 在views.py中,创建包含要在元组中

我有一个月回报率的股票投资组合。目前,报税表存储在数据库中,作为每个月的第一天和每年的第一天。 因此,2016年1月1日-5% 2016年2月1日-3%

在Django模板中显示此内容的最佳方式是什么? 我希望每年都有一个单独的行,列是日期,因此:

     Jan  Feb  Mar  Apr....
2014
2015
2016
什么是将月度回报置于正确位置的最佳方法


谢谢你的帮助

我不知道这是否是最好的方法,但我最终使用了一个元组列表来实现这一点

在views.py中,创建包含要在元组中显示的行的字典条目,并列出这些行:

def testview(request):
   x = [(2014,1,2,3),(2015,4,5,6),(2016,7,8,9)]
   return render(request, 'yourtemplate.html', {'data':x})
接下来在模板(yourtemplate.html)中创建一个js表,并在这些行上循环

<table>
  <tr>
    <th></th>
    <th>Jan</th>
    <th>Feb</th>
    <th>Mar</th>
   </tr>

{% for tuple in data %}
   <tr>
      <th>{{tuple.0}}</th>
      <th>{{tuple.1}}</th>
      <th>{{tuple.2}}</th>
      <th>{{tuple.3}}</th>
   </tr>
{% endfor %}
</table>

简
二月
破坏
{数据%中的元组为%1}
{{tuple.0}}
{{tuple.1}}
{{tuple.2}}
{{tuple.3}}
{%endfor%}
我希望这有帮助