bbs的后台管理页面搭建

1.开设后台管理页面url

image

2.后台管理页面前端页面搭建

后台管理页面采用页面继承的特性,搭建模板,后面对应页面继承母版就行!

导航条部分拷贝前面的base.html就行

侧边栏部分采用bootstrap中下面这一部分:
image

主面板采用bootstrap中的标签页部分!

3.后台管理视图函数搭建

中间包含分页器的插入使用!

from utils.mypage import Pagination

def backend(request):
    article_list = models.Article.objects.filter(blog = request.user.blog)
    current_page = request.GET.get("page", 1)
    all_count = article_list.count()
    page_obj = Pagination(current_page=current_page, all_count=all_count, per_page_num=10)
    page_queryset = article_list[page_obj.start:page_obj.end]
    return render(request,'backend/backend.html',locals())

4.后台文章页展示

{% extends 'backend/base.html' %}

{% block article %}
    <table class="table table-striped table-hover">
        <thead>
        <tr>
            <th>标题</th>
            <th>评论数</th>
            <th>点赞数</th>
            <th>点踩数</th>
            <th>操作</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {% for article in page_queryset %}
            <tr>
                <td><a href="/{{ request.user.username }}/article/{{ article.pk }}/">{{ article.title }}</a></td>
                <td>{{ article.comment_num }}</td>
                <td>{{ article.up_num }}</td>
                <td>{{ article.down_num }}</td>
                <td><a href="">编辑</a></td>
                <td><a href="">删除</a></td>
            </tr>
        {% endfor %}
        </tbody>
        </table>
    <div class="pull-right">
    {{ page_obj.page_html|safe }}
    </div>

{% endblock %}

posted @ 2022-10-10 20:28  等日落  阅读(62)  评论(0编辑  收藏  举报