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

相关推荐
起予者汝也9 分钟前
Python 数据结构
开发语言·数据结构·python
LadenKiller10 分钟前
2026年量化工具增量,放回回测模拟实盘阶段判断
人工智能·python
石一峰69914 分钟前
驱动:私有数据为什么要在三个地方各挂一遍?
数据库·python·算法
2601_9563198818 分钟前
最新量化软件怎么选,先按能力短板匹配工具类型
人工智能·python
卷无止境21 分钟前
Apache Ossie:打破数据孤岛的语义互操作标准
后端·数据分析
晓杰在写后端25 分钟前
从0到1实现Balatro游戏后端(11):商店商品池与运行时商品实例生成
后端·游戏开发
Tbisnic32 分钟前
26.AI大模型:RNN、LSTM、GRU
人工智能·python·rnn·gru·大模型·llm·lstm
七夜zippoe1 小时前
OpenClaw 实战:智能文档助手——从问答到生成的完整方案
人工智能·python·机器学习·openclaw·智能文档
AskHarries1 小时前
OAuth 登录怎么接
后端
卡提西亚2 小时前
leetcode-179. 最大数
python·算法