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

相关推荐
wing98几秒前
从codex转战workbuddy使用一周的感受
前端·人工智能·后端
EatFan7 分钟前
Java接入支付宝 JSAPI 支付保姆教程(二):流程讲解与前后端代码讲解
前端·spring boot·后端·微信小程序·小程序·uni-app
zhangzeyuaaa9 分钟前
Python requests:raise_for_status() 与 4xx/5xx 异常层次详解
开发语言·python
泡海椒16 分钟前
动态代理核心原理:JQuick-Java接口规则自动生成机制解析
java·开发语言·python
余槐i24 分钟前
Firecrawl 实战:将网站转换为大模型可用数据
人工智能·python·工具·firecrawl
shirsl25 分钟前
算法 Day 2 滑动窗口 + 栈 / 单调栈
开发语言·python·算法
步行cgn26 分钟前
Spring 启动报错:BeanFactory not initialized 的原因与解决
java·python·spring
步行cgn35 分钟前
Spring 报错:No bean class specified on bean definition 的原因与解决
java·后端·spring
凤山老林41 分钟前
Spring Boot 整合 Flowable 的企业级落地指南
数据库·spring boot·后端·flowable·工作流
苏三说技术1 小时前
Kafka已正式接入AI
后端