django admin 自定义界面时丢失左侧导航 nav_sidebar

只显示了自定义模板的内容,左侧导航没有显示出来。

原因:context 漏掉了,要补上。

复制代码
# 错误写法(左侧导航不显示)

    def changelist_view(self, request, extra_context=None):
        form = CsvImportForm()
        payload = {"form": form}
        return TemplateResponse(request, "admin/csv_form.html", payload)




# 正确写法:========================

    def changelist_view(self, request, extra_context=None):
        form = CsvImportForm()# 我要用的内容


        # 引入原有的内容
        context = dict(
            # Include common variables for rendering the admin template.
            self.admin_site.each_context(request),  # side nav was not loading because this was not added.
            # Anything else you want in the context...
            # key=value,

            form= form        # 加上我要用的内容

        )

        return TemplateResponse(request, "admin/csv_form.html", context)

How to add left sidebar in custom django admin template - Stack Overflow

相关推荐
小玮看世界几秒前
[Python]螺旋遍历 vs 最短路径:方向控制类算法的“同源异流”
开发语言·python·算法
MeetTanG2 分钟前
Go 实战锦囊|errgroup:优雅地管理并发任务组
后端·go
PragmaticWorks11 分钟前
DDD 学了很多却用不上?因为你把“责任”和“时机”揉在了一起
后端·领域驱动设计
OPEN-F11 分钟前
ROS2系列教程:tf2坐标变换详解(C++/Python)
开发语言·c++·python
2601_9620973616 分钟前
Python工作流实战:SpiffWorkflow深度应用与BPMN自动化指南
python·自动化·工作流·bpmn·spiffworkflow
凯哥Java21 分钟前
System.setProperty 的正确姿势:Spring Boot 启动类里的“缺省值“魔法
java·spring boot·后端
柯克七七25 分钟前
Vue刷新页面数据重置?一招解决Vuex状态丢失
后端
楚兴28 分钟前
ACP 到底解决了什么?让 IDE 和 Coding Agent 解耦
人工智能·后端·架构
楚兴37 分钟前
DeepSeek Harness 到底在做什么?拆开 Agent 的运行时
人工智能·后端·架构
baopixiaoz39 分钟前
BeeQuant × BeeAgent:AI驱动智能交易
大数据·人工智能·python·区块链