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

相关推荐
大蚂蚁2号几秒前
本地批量音视频转文本免费工具
python·音视频·开源软件
小刘|4 分钟前
Spring AI 结构化输出 + 大模型参数全解(含千问调优)
java·后端·spring
copyer_xyf6 分钟前
FastAPI 项目骨架搭建
前端·后端·python
十正7 分钟前
aiohttp.TCPConnector 连接池原理详解
网络·python·tcp·aiohttp
LoserChaser11 分钟前
Flask 文件上传服务器 - 知识点总结
服务器·python·flask
cd9888012 分钟前
2026年,哪家电销机器人定制更灵活?
python
二十七剑14 分钟前
LangGraph 源码深度解析:_branch.py 条件分支底层实现原理
python
laowangpython18 分钟前
tokio-rstracing:Rust 可观测性的标准答案
开发语言·后端·其他·rust
IT_陈寒20 分钟前
Python虚拟环境的这个坑,我居然绕了三天才爬出来
前端·人工智能·后端
KaMeidebaby21 分钟前
卡梅德生物技术快报|噬菌体展示文库构建全流程解析 | 大豆球蛋白纳米抗体筛选实践
人工智能·python·tcp/ip·算法·机器学习