Javascript, Html, Dango data transition[1]

Generate a dynamic table with javascript in Dango

  • Configuration:
    • Dango 2.0
    • Python 3.6.5
    • Javacript

my/bs/urls.py

from django.shortcuts import render
# Create your views here.
from django.conf.urls import url
from . import views
urlpatterns = [
    **url(r'^bs5$', views.bs_bs5, name="bootstrap_bs5"),**
]

my/bs/urls.py

## add a new row ##
def bs_bs5(request):
    tests1 ={'number':'111','name':'hans','labs':'Tsinghua'}

    tests2 ={'a':{'number':'121','name':'hans','labs':'Tsinghua'},
             'b':{'number':'123','name':'amy','labs':'Peking'}}

    print(tests1)
    print(tests2)

    return render(request, 'bs5.html', {'tests2': tests2} )

my/static/html/bs5.html

<body>
  <!-- container section start -->
  <table class="table table-hover">
      <caption>Table hello</caption>
      <thead>
          <tr>
              <th>Number</th>
              <th>Standard</th>
              <th>Labs</th>
          </tr>
      </thead>
      <tbody>
          {% for k,v  in tests2.items%}
          <tr>
              {% for k1,v1  in v.items%}
              <td>{{ v1 }}</td>
              {% endfor %}
          </tr>
          {% endfor %}


      </tbody>
  </table>
 </body>

Result in the web:

这里写图片描述

猜你喜欢

转载自blog.csdn.net/wondervictor/article/details/79221045