Я пытаюсь найти расположение параметра URL /info/getips/
в функции GetJSON. Ниже мой код. Я использую Ubuntu. это проект Djongo:
Файл: Board.js
dashboard.getIps = function() {
$.getJSON('/info/getips/', function(data) {
var psTable = $("#get_ips").dataTable({
aaData: data,
aoColumns: [{
sTitle: "INTERFACE"
},
{
sTitle: "MAC ADDRESS"
},
{
sTitle: "IP ADDRESS"
},
{
sTitle: "IP ADDRESS",
sDefaultContent: "unavailable"
}
],
bPaginate: false,
bFilter: true,
sDom: "lrtip",
bAutoWidth: false,
bInfo: false
}).fadeIn();
$filterPs.on("keyup", function() {
psTable.fnFilter(this.value);
});
});
};
Файл: view.py
def get_ipaddress():
"""
Get the IP Address
"""
data = []
try:
eth = os.popen("ip addr | grep LOWER_UP | awk '{print $2}'")
iface = eth.read().strip().replace(':', '').split('\n')
eth.close()
del iface[0]
for i in iface:
pipe = os.popen("ip addr show " + i + "| awk '{if ($2 == \"forever\"){!$2} else {print $2}}'")
data1 = pipe.read().strip().split('\n')
pipe.close()
if len(data1) == 2:
data1.append('unavailable')
if len(data1) == 3:
data1.append('unavailable')
data1[0] = i
data.append(data1)
ips = {'interface': iface, 'itfip': data}
data = ips
except Exception as err:
data = str(err)
return data
def getips(request):
"""
Return the IPs and interfaces
"""
try:
get_ips = get_ipaddress()
except Exception:
get_ips = None
data = json.dumps(get_ips['itfip'])
response = HttpResponse()
response['Content-Type'] = "text/javascript"
response.write(data)
return response
Файл index.html
<div class="span6">
<div class="widget widget-table action-table">
<div class="widget-header"> <i class="fa fa-level-up"></i>
<h3>IP Adresses</h3><i class="fa fa-minus"></i>
<div id="refresh-ip">
</div>
</div>
<!-- /widget-header -->
<div class="widget-content">
<table id="get_ips" class="table table-hover table-condensed table-bordered">
</table>
</div>
<!-- /widget-content -->
</div>
<!-- /widget -->
</div>
$ (функция pageLoad () {
board.getIps();
});