Created
March 13, 2019 23:30
-
-
Save nenodias/7a5949053190308c6d0351c0ddd002e5 to your computer and use it in GitHub Desktop.
Ajuda django
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Document</title> | |
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" /> | |
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.5.6/css/buttons.dataTables.min.css" /> | |
<script src="https://code.jquery.com/jquery-3.3.1.js"></script> | |
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script> | |
<script src="https://cdn.datatables.net/buttons/1.5.6/js/dataTables.buttons.min.js"></script> | |
<script src="https://cdn.datatables.net/buttons/1.5.6/js/buttons.print.min.js"></script> | |
<script src="https://cdn.datatables.net/buttons/1.5.6/js/buttons.colVis.min.js"></script> | |
</head> | |
<body> | |
<table id="example" class="display" style="width:100%"> | |
<thead> | |
<tr> | |
{% for f in lista %} | |
<th>{{f}}</th> | |
{% endfor %} | |
</tr> | |
</thead> | |
<tbody> | |
{% for row in json %} | |
<tr> | |
{% for valor in row.fields.values %} | |
<td>{{ valor }}</td> | |
{% endfor %} | |
</tr> | |
{% endfor %} | |
</tbody> | |
<tfoot> | |
<tr> | |
{% for f in lista %} | |
<th>{{f}}</th> | |
{% endfor %} | |
</tr> | |
</tfoot> | |
</table> | |
<script> | |
$(document).ready(function () { | |
$('#example').DataTable({ | |
dom: 'Bfrtip', | |
buttons: [ | |
{ | |
extend: 'print', | |
exportOptions: { | |
columns: ':visible' | |
} | |
}, | |
'colvis' | |
], | |
columnDefs: [{ | |
targets: -1, | |
visible: false | |
}] | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render | |
from django.views.generic import TemplateView | |
# Create your views here. | |
class LsmcDashboardView(TemplateView): | |
template_name = 'index.html' | |
def get_context_data(self, **kwargs): | |
context = super().get_context_data(**kwargs) | |
data = [ | |
{ | |
"model": "x9.equipment", | |
"pk": 46, | |
"fields": { | |
"ip": "177.126.190.1", | |
"name": "gw1.sp2", | |
"equipment_number": None, | |
"protocol": None, | |
"site": 2, | |
"cage": None, | |
"rack": None, | |
"vlan_list": "", | |
"active": True, | |
"xchange_id": None, | |
"flow_server": "76.191.126.177.static.sp2.alog.com.br", | |
"loopback": None, | |
"ntp": "null", | |
"syslog": "null", | |
"tacacs": "null", | |
"timezone": "", | |
"trap": "null", | |
"version": "14.2R6.5", | |
"chassis_description": "MX480" | |
} | |
}, | |
] | |
lista = data[0]['fields'].keys() | |
context['json'] = data | |
context['lista'] = lista | |
return context |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment