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

相关推荐
counting money22 分钟前
Java IO流详解:从InputStream到文件操作实战
java·开发语言·python
坚持学习前端日记1 小时前
Python SQLAlchemy ORM 从0到1精通实战手册(基础到复杂高阶)
数据库·python·oracle
北斗落凡尘1 小时前
LangGraph 入门实战(11)--输出模式
后端·python·langchain
雪碧聊技术2 小时前
安装Python(保姆级教程)
python·版本更新·python下载
++==2 小时前
JSON和Python的 四种核心容器
python·json
demo007x2 小时前
Hermes-Agent 技术架构
前端·后端·agent
__zRainy__4 小时前
Node系列 · Node基础:net 模块
后端·node.js
Diligently_4 小时前
Anolis 系统更新与密码设置&磁盘扩容
java·后端·spring
kyson_4 小时前
大文件切片上传:从“能传”到“可靠”的 Vue 3 + Java 全栈实现
后端