您好,登錄后才能下訂單哦!
直接上代碼:
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 %}
效果如圖:
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。