Python Django数据表视图不';不显示数据表,仅显示json
我对python、django和javascript非常陌生。在我的localhost站点上显示任何内容都是一个突破,但现在我尝试将其显示为datatable,我认为它只是作为原始json数据填充。我猜这可能是模板中的某个原因造成的,但我是一个新手,所以非常感谢您的帮助 Models.pyPython Django数据表视图不';不显示数据表,仅显示json,python,json,django,datatable,Python,Json,Django,Datatable,我对python、django和javascript非常陌生。在我的localhost站点上显示任何内容都是一个突破,但现在我尝试将其显示为datatable,我认为它只是作为原始json数据填充。我猜这可能是模板中的某个原因造成的,但我是一个新手,所以非常感谢您的帮助 Models.py from django.db import models 职业投手(型号.型号): url.py from django.conf.urls import url from analyzer import
from django.db import models
职业投手(型号.型号):
url.py
from django.conf.urls import url
from analyzer import views
from analyzer.views import pitcherlist
import json
urlpatterns = [
url(r'^$', pitcherlist.as_view(), name='pitcherlist_json'),
]
views.py
from django.shortcuts import render
from .models import pitcher
from django_datatables_view.base_datatable_view import BaseDatatableView
import json
from django.http.response import HttpResponse
class pitcherlist(BaseDatatableView):
model = pitcher
columns = ['player_name', 'game_date','pitch_type', 'pfx_x']
max_display_length = 500
模板
<!DOCTYPE html>
<html>
<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css"/>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.3.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
<head>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-12 col-md-12">
<div class="well">
<table id="pitcherlist" class="display responsive" width="100%">
<thead>
<tr>
<th width="5%">player_name</th>
<th width="5%">game_date</th>
<th width="5%">pitch_type</th>
<th width="5%">pfx_x</th>
<th width="5%"></th>
</tr>
</thead>
</table>
</div>
</div>
</div>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
var oTable: $('#pitcherlist').dataTable({
"processing": true,
"serverSide": true,
"ajaxSource": {% url 'pitcherlist_json' %}
});
</script>
</body>
</html>
玩家姓名
比赛日期
俯仰式
pfx_x
$(文档).ready(函数(){
变量可调:$('#投手列表')。数据表({
“处理”:对,
“服务器端”:正确,
“ajaxSource”:{%url'PitchrList_json%}
});
这是输出:
{“draw”:0,“recordsTotal”:171,“recordsFiltered”:171,“data”:
[2017-07-31”、“FF”、-0.6053]、“赫克托·内里斯”,
“2017-07-31”、“FS”、-1.1989)、“赫克托·尼里斯”、“2017-07-31”、“FF”,
-0.7938]、“赫克托-内里斯”、“2017-07-31”、“FF”、-0.7876]、“赫克托-内里斯”、“2017-07-31”、“FF”、-0.8419]、“赫克托-内里斯”、“2017-07-31”,
“FF”、-0.9699]、“赫克托·尼里斯”、“2017-07-31”、“FF”、-0.8357],
[“赫克托-内里斯”,“2017-07-31”,“FS”,“0.8772”,“赫克托-内里斯”,
“2017-07-31”、“FF”、-0.6558)、“赫克托·尼里斯”、“2017-07-31”、“FF”,
-0.6579],“结果”:“确定”}
检查此项。您必须执行以下操作:
<table>
{% for x in pitcherlist%}
<tr>
<th width="5%">player_name</th>
<th width="5%">game_date</th>
<th width="5%">pitch_type</th>
<th width="5%">pfx_x</th>
</tr>
<td>{{ x.player_name}}</td>
<td>{{ x.game_date}}</td>
<td>{{ x.pitch_type}}</td>
<td>{{ x.pfx_x}}</td>
</tr>
{% endfor %}
</table>
{Pitchrlist%中x的%s}
玩家姓名
比赛日期
俯仰式
pfx_x
{{x.player_name}
{{x.game_date}
{x.pitch_type}
{x.pfx_x}
{%endfor%}
与其在此处转储所有代码,不如尝试创建一个。这可能有助于您自己发现问题,如果没有,它肯定会帮助我们帮助您诊断问题。对不起,我想我应该彻底检查一下,因为我不确定问题出在何处。
<table>
{% for x in pitcherlist%}
<tr>
<th width="5%">player_name</th>
<th width="5%">game_date</th>
<th width="5%">pitch_type</th>
<th width="5%">pfx_x</th>
</tr>
<td>{{ x.player_name}}</td>
<td>{{ x.game_date}}</td>
<td>{{ x.pitch_type}}</td>
<td>{{ x.pfx_x}}</td>
</tr>
{% endfor %}
</table>