码迷,mamicode.com
首页 > 数据库 > 详细

django自定义sql返回元组的处理

时间:2018-06-13 23:35:13      阅读:624      评论:0      收藏:0      [点我收藏+]

标签:web

1.views.py

def scheduling(request):
    cursor = connection.cursor()
    cursor.execute("select staff_name from alarm_platform.TBL_STAFF where staff_number=any(select duty_staff_number1 from alarm_platform.TBL_DUTY);",None)
    people_list = cursor.fetchall()
    print(people_list)
    return render(request, "people_list.html", {"people_list": people_list})  # 返回界面
  1. 模板文件

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Store</title>
    </head>
    <body>
    <table border="1">
    <thead>
    <tr>
        <th>第一</th>
    </tr>
    </thead>
    <tbody>
    {% for people_list in people_list %}
        <tr>
    
            <td>{{ people_list.0 }}</td>
        </tr>
    {% endfor %}
    </tbody>
    </table>

    你可以在模板把 {{ chika }} 打印出来:

    ((‘wangxa‘,), (‘wangcha‘,), (‘liuli‘,), (‘wangkke‘,))
  {% for people_list in people_list %}
     {{ people_list.0 }} {{ people_list.1}} {{ people_list.2 }}   
{% endfor %}

django自定义sql返回元组的处理

标签:web

原文地址:http://blog.51cto.com/13675040/2129099

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!