我正在尝试在Django中使用json将Ajax json url更改为python变量。正如你所看到的,这两种情况下的url是一样的,所以我不能理解这是怎么回事。提前谢谢。
我正在寻找但不能工作的东西
<script>
$(document).ready(function() {
var table = $('#users').DataTable({
"ajax": "{{ es_docs }}",我的观点是:
@login_required(login_url="/login/")
def index(request):
context = {}
context['segment'] = 'index'
html_template = loader.get_template( 'index.html' )
resp = requests.get("https://gyrocode.github.io/files/jquery-datatables/arrays_id.json").json()
context['es_docs'] = resp
return HttpResponse(html_template.render(context, request))Template.html:
<script>
$(document).ready(function() {
var table = $('#users').DataTable({
"ajax": "https://gyrocode.github.io/files/jquery-datatables/arrays_id.json",
'columnDefs': [
{
'targets': 0,
'checkboxes': {
'selectRow': true
}
}
],
'select': {
'style': 'multi'
},
'order': [[1, 'asc']]
});发布于 2021-05-22 04:01:21
这一点:
resp = requests.get(...)
返回response对象。要获取json数据,请执行以下操作:
response = requests.get(...)
if response.status_code != 200:
# handle errors:
else:
json_data = response.json()
context['es_docs'] = json_datahttps://stackoverflow.com/questions/67643050
复制相似问题