【问题标题】:How to create different table for different data value for Google App Engine如何为 Google App Engine 的不同数据值创建不同的表
【发布时间】:2018-03-31 12:53:09
【问题描述】:

我正在使用 Google App Engine webapp2 框架构建一个简单的网站来统计和收集所有提交的投标。我已经从名为“预订”的数据库中读取了每个出价。

目前,对于所有提交的投标,只有一个表格可以显示。我如何使用 jinja2 为不同的 IssueName 创建不同的表。

例如,如果IssueName=Bond1,则表1收集了bond1的所有出价;如果IssueName=Bond2,则表2收集了bond2的所有投标

<table class="table table-striped">
                <thead>
                    <tr>
                        <th>IssueName</th>
                        <th>RM Name</th>
                        <th>Customer</th>
                        <th>Price</th>
                        <th>Notional</th>
                        <th>Bid Time</th>
                    </tr>
                </thead>
                {% for bid in Book %}
                    <tbody>
                        <tr>
                            <th>{{ bid.IssueName }}</th>
                            <th>{{ bid.RMName }}</th>
                            <th>{{ bid.CustomerName }}</th>
                            <th>{{ bid.BidPrice }}</th>
                            <th>{{ bid.Notional }}</th>
                            <th>{{ bid.BidTime }}</th>
                        </tr>
                    </tbody>
                {% endfor %}
                </table>

【问题讨论】:

    标签: google-app-engine jinja2 webapp2


    【解决方案1】:

    您有一个名为 Book 的数据库?还是 NDB 数据存储中名为 Book 的种类(表)?我假设你的意思是你有一种叫做书的东西。您的请求处理程序看起来像这样吗?

    from webapp2_extras import jinja2
    
    class BidsRequestHandler(webapp2.RequestHandler):
        def get(self):
            j = jinja2.Jinja2(self.app)
            self.response.write(j.render_template('bids.html', **{
                'Book': Book.query().fetch(),
            }))
    

    为了使用 jinja,你需要在你的 app.yaml 中使用这个

    libraries:
    - name: jinja2
      version: "2.6"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多