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

相关推荐
circuitsosk31 分钟前
NL2SQL在工业级场景下的精度优化:Schema Linking + 动态Few-shot实战
人工智能·python·sql·大模型·nl2sql
kobe_OKOK_6 小时前
DRF接口幂等操作
python·django
SomeB1oody6 小时前
【RustyML入门】6.3. 并行归约
开发语言·后端·机器学习·rust·教程
廿士7 小时前
python脚本使用相关
python
青 春 记 忆7 小时前
零基础入门python19:Flask账本第一步——应用工厂、蓝图和健康检查
python·flask·后端开发
朦胧之7 小时前
Python 后端核心知识
python
Profile排查笔记7 小时前
指纹浏览器哪个好?从 Profile、代理、权限和自动化能力判断是否适合
前端·人工智能·后端·自动化
用户938515635077 小时前
用 AI 结对编程从 0 搭一个"单词后台管理系统":Next.js + Supabase + Drizzle + shadcn/ui 全记录
后端·postgresql·next.js
denggun123458 小时前
yield
前端·数据库·python
爱学习的小邓同学8 小时前
Golang --- (1)第一个Golang程序
开发语言·后端·golang