第一个版本
This commit is contained in:
23
status/views.py
Normal file
23
status/views.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from django.shortcuts import render
|
||||
from django.http import JsonResponse
|
||||
from .models import Service
|
||||
|
||||
# 主页视图
|
||||
def home(request):
|
||||
return render(request, 'status/index.html')
|
||||
|
||||
# API视图 - 获取所有服务状态
|
||||
def get_services(request):
|
||||
services = Service.objects.all()
|
||||
data = []
|
||||
for service in services:
|
||||
data.append({
|
||||
'name': service.name,
|
||||
'status': service.status,
|
||||
'description': service.description,
|
||||
'ip_address': service.ip_address,
|
||||
'port': service.port,
|
||||
'reliability': float(service.reliability),
|
||||
'last_updated': service.last_updated.isoformat()
|
||||
})
|
||||
return JsonResponse(data, safe=False)
|
||||
Reference in New Issue
Block a user