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

相关推荐
贝壳6904 小时前
bool-hybrid-array 9.13.6 偷偷加了个"按键自动升序"的字典,我翻出来测了下
python
紧跟先前的步伐4 小时前
Go AI Agent 实战 28|Agent 的预算、超时与停止条件
开发语言·人工智能·后端·ai·golang
Hespethorn4 小时前
112 个 Valgrind 错误,1 个根因:C++ 多线程服务的关机顺序复盘
后端·架构
小兔子5 小时前
new Date('2024-01-01') 和 new Date('2024/01/01') 差在哪
后端
艺杯羹5 小时前
MCP本地服务集成避坑:从Stdio管道僵死到双向JSON-RPC稳健通信
人工智能·python·ai·系统架构·大语言模型·ai编程·mcp
happylifetree5 小时前
Python78:核心语法-面向对象基础-类与对象
python
duansamve5 小时前
Python中进程
python
日日大王学编程6 小时前
AI Agent 技术发展历程、演进逻辑与技术范式综述
人工智能·python
春涧草茶6 小时前
慢就是快16-1协程
开发语言·前端·python
Oiiouui6 小时前
linux服务器部署Logto后端与对应前端的实现
linux·服务器·前端·后端