def olink_lists(request):
from django.db import connection
with connection.cursor() as cursor:
page = request.POST['page']
limit = request.POST['limit']
start = (int(page) - 1) * int(limit)
cursor.execute(
"SELECT w.api_table_name,count(*) AS nums FROM app_tfurl AS t LEFT JOIN app_webcf AS w ON t.y_webcf_id=w.webcf_id WHERE w.api_table_name LIKE 'www.%' GROUP BY w.api_table_name")
lists = cursor.fetchall()
count = len(lists)
cursor.execute(
"SELECT w.api_table_name,count(*) AS nums FROM app_tfurl AS t LEFT JOIN app_webcf AS w ON t.y_webcf_id=w.webcf_id WHERE w.api_table_name LIKE 'www.%' GROUP BY w.api_table_name LIMIT {},{}".format(start, limit))
page_list = dictfetchall(cursor)
data = {"code": 0, "msg": "", "count": count, "data": page_list}
return JsonResponse(data, safe=False)
def dictfetchall(cursor):
return [dict(zip([col[0] for col in cursor.description], row)) for row in cursor.fetchall()]
django原生查询的用法
最新推荐文章于 2023-07-06 20:26:04 发布