我试图在代码中使用datables js,但是我的页面仍然是空的(没有标题和表)
我尝试了几次代码修改,但仍然保持空白页没有错误消息
html页:
{% extends "baseCRM.html" %}
{% load bootstrap4 %}
<link rel="stylesheet" type="text/css" href="/static/DataTables/datatables.css">
<script type="text/javascript" charset="utf8" src="/static/DataTables/datatables.js"></script>
{% block content %}
<table cellpadding="0" cellspacing="0" border="0" id="example">
<thead>
<tr><th>Client List</th></tr>
</thead>
<tbody></tbody>
</table>
<script type="text/javascript" language="javascript" class="init">
$(document).ready(function() {
$('#example').dataTable( {
"processing": true,
"ajax": {
"processing": true,
"url": "{% url 'clientListJson' %}",
"dataSrc": ""
},
"columns": [
{ "data": "fields.name" },
{ "data": "pk" }
]
} );
} );
</script>
{% endblock %}
你知道吗视图.py地址:
def client_list_json(request):
object_list = Client.objects.all().order_by("name")
json = serializers.serialize('json', object_list)
return HttpResponse(json, content_type='application/json')
你知道吗型号.py你知道吗
class Client(models.Model):
name = models.CharField(max_length=255,)
description = models.CharField(max_length=255,blank=True)
address1 = models.CharField("Address line 1",max_length=1024,)
address2 = models.CharField("Address line 2",max_length=1024,)
zip_code = models.CharField("ZIP / Postal code",max_length=12,)
city = models.CharField("City",max_length=1024,)
country = models.CharField("Country",max_length=3,choices=ISO_3166_CODES,)
point_person = models.ForeignKey(User, limit_choices_to={'is_staff': True}, on_delete=models.CASCADE) # in charge of the client (admin)
firm = models.ManyToManyField(Firm, related_name='Firm_Client',)
你知道吗网址.py你知道吗
path('client\u list\u json/',views.client\列表\u json,name='clientListJson')
我应该有一份客户名单,包括姓名、描述、公司和联系人
这里我使用jQueryCDN,DataTableCDN。你知道吗
您的Ajax URL无法正常工作:
您的代码:
更新代码:
**
**
Html页面:我把它命名为anothor.html
为测试添加一个额外的URL。你知道吗
相关问题 更多 >
编程相关推荐