直接上代码:
models.py
django.db models Asset(models.Model): OS_CHOICE = [ (, ), (, ), (, ), (, ), (, ), ] hostname = models.CharField(=, =, =) ip = models.GenericIPAddressField(=, =) port = models.IntegerField(=, =) username = models.CharField(=, =) password = models.CharField(=, =) os = models.CharField(=OS_CHOICE, =, =, =) is_active = models.BooleanField(=, =) (): .hostname
views.py
django.shortcuts get_object_or_404,render django.http HttpResponse django.views.generic ListView, CreateView, DetailView, View, UpdateView django.urls reverse_lazy django.core.paginator Paginator,EmptyPage,PageNotAnInteger .forms AssetForm .models Asset users.mixins LoginRequiredMixin page_list(request): assets = Asset.objects.all() paginator = Paginator(assets,) page = request.GET.get() page: article_list = paginator.page(page).object_list : article_list = paginator.page().object_list : customer = paginator.page(page) PageNotAnInteger: customer = paginator.page() EmptyPage: customer = paginator.page(paginator.num_pages) render(request,,{:customer,:article_list})
template模板
主机名 IP 端口 管理账号 系统 Active 操作 {% for asset in articles %} {{ asset.hostname }} {{ asset.ip }} {{ asset.port }} {{ asset.username }} {{ asset.get_os_display }} {% if not user.is_active %} 否 {% else %} {% endif %} {% endfor %} {% if cus_list.has_previous %} {% endif %} {% for pg in cus_list.paginator.page_range %} {% if cus_list.number == pg %} {{ pg }}{% else %} {{ pg }}j8-3 {% endif %} {% endfor %} {% if cus_list.has_next %} {% endif %}
效果如图:
时间: 2024-10-01 12:53:44