django 扩展为admin/base.html的自定义页面中不显示边栏菜单

rbpvctlc  于 2023-05-19  发布在  Go
关注(0)|答案(1)|浏览(224)

我已经创建了一个自定义页面,我想在Django管理面板中显示。我使用jazzmin管理模板为我的django项目。

**问题:**我没有得到边栏菜单唯一的选项,我可以看到是 Jmeter 板。为什么会发生这种情况,我如何获得完整的侧边栏菜单,我得到的所有页面的模型在admin.py注册

我的Views.py

from confluent_kafka.admin import AdminClient, NewTopic
from base.constants import KAFKA_CONFIG
from django.views.generic import TemplateView

# Create your views here.
KAFKA_EXCLUDE_TOPICS = {'__consumer_offsets': True}

class QueueOperationsView(TemplateView):
    template_name = 'dataprocessing/queue_management/queue.html'

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        admin_client = AdminClient(KAFKA_CONFIG)
        topic_metadata = admin_client.list_topics()
        has_purge_permissions = self.request.user.has_perm('masters.purge_dataprocessingqueuemaster')

        # add your context data here
        context['topics'] = [i for i in topic_metadata.topics if i not in KAFKA_EXCLUDE_TOPICS]
        context['has_purge_permissions'] = has_purge_permissions
        return context

我的Urls.py

from basics.admin import wrap_admin_view
from masters.views import QueueOperationsView
from django.conf.urls import url

url(r'^admin/queue-management/$', wrap_admin_view(QueueOperationsView.as_view()), name="queue_operations_view"),

wrap_admin_view():

def wrap_admin_view(view, cacheable=False):
    """
    Use this to wrap view functions used in admin dashboard
    Note: Only the views that require a admin login
    """
    from django.contrib import admin

    def wrapper(*args, **kwargs):
        return admin.site.admin_view(view, cacheable)(*args, **kwargs)

    wrapper.admin_site = admin.site
    return update_wrapper(wrapper, view)

模板:

{% extends 'admin/base.html'%}
{% load static %}
{% block content %}
<div class="container-fluid">

    
</div>
{% endblock %}

{% block additional_scripts %}
{{ block.super }}
{% include "dataprocessing/queue_management/queue_management_options.html" %}
{% include "dataprocessing/queue_management/queue_management_table.html" %}
{% include "dataprocessing/queue_management/queue_management_table_loading.html" %}
<script src="{% static 'js/admin/queue_management/queue_management.js' %}"></script>
{% endblock %}
5f0d552i

5f0d552i1#

我今天也遇到了同样的问题。出于某种原因,我必须在上下文中提供可用应用程序的列表。我是在一个view方法中完成的,所以我不确定它是否100%适用于您所编写的内容,但这是我的解决方案。

context = {"available_apps": self.admin_site.each_context(request).get("available_apps")}

相关问题