oldbee0925 2022-06-24 14:08 采纳率: 91.4%
浏览 28
已结题

django 初始页面加载与ajax返回dict,调用dict有何不同?

我有在初始页面以及互动后加载表格的需求。在初始页面加载中,我这样写没错:

在django中,我用这样的方式返回初始页面:
return HttpResponse(template.render(context, request))
其中,G_view是字典(dict)context的一项。
然后在模板页面中,这样写没问题。
 <tr>
                                                    <th>{{G_view.columns.0}}</th>
                                                    <th>{{G_view.columns.1}}</th>
                                                    <th>{{G_view.columns.2}}</th>
                                                    <th>{{G_view.columns.3}}</th>
                                                    <th>{{G_view.columns.4}}</th>
                                                    <th>{{G_view.columns.5}}</th>
                                                    <th>{{G_view.columns.0}}</th>
                                                  </tr>
                                                </thead>
                                                <tbody>
                                            {% for data in G_view.data %}
                                                 <tr class={{data.7}}>
                                                    <td>{{data.0}}</td>
                                                    <td>{{data.1}}</td>
                                                    <td>{{data.2}}</td>
                                                    <td>{{data.3}}</td>
                                                    <td>{{data.4}}</td>
                                                    <td>{{data.5}}</td>
                                                     <td>{{data.0}}</td>
                                              </tr>
                                            {% endfor %}


在ajax中,返回了一个data,是在django中通过如下操作产生的dict:

R_D_bend = R_D_bend.to_dict(orient='split') #dataframe转化为dict类型
return HttpResponse(R_D_bend)#向页面返回字典

我想用返回的这个字典生成一个表格,按照上例的代码没有反应,请问是什么问题?我该怎么做?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 7月2日
    • 创建了问题 6月24日

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog