python - 修改 django 管理模板

标签 python django django-templates django-admin

我正在使用 Django 框架在 python 中编写应用程序,我试图弄清楚是否有可能修改特定模块的现有 django 管理应用程序模板(change_form.html、base_site.html...)。在文件夹项目中,我已经将 templates/admin 目录放在修改管理应用程序模板的位置,但对于一个特定模块,我想使用不同的模板。特定模块位于单独的应用程序中。

如果您能让我知道如何实现这一目标,或者至少指出我可以找到它的文档,我将不胜感激。

提前非常感谢您。

最佳答案

您可以通过在您希望其自定义的级别覆盖特定模板来实现此目的。例如,如果您想修改应用程序的 change_form.html,您可以在 templates/admin/中创建(或从 contrib/admin/templates 复制 change_form.html...)模板yourapp/change_form.html。对于应用中的模型,您可以将其放置在 templates/admin/yourapp/yourmodel/change_form.html 中。您可以找到更多信息here

来自上面的链接:

For example, if we wanted to add a tool to the change list view for all the models in an app named my_app, we would copy contrib/admin/templates/admin/change_list.html to the templates/admin/my_app/ directory of our project, and make any necessary changes.

If we wanted to add a tool to the change list view for only a specific model named ‘Page’, we would copy that same file to the templates/admin/my_app/page directory of our project.

关于python - 修改 django 管理模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32975763/

相关文章:

Python time.sleep() 遇到浮点异常

python - 如何执行交互式外部命令?

css - 考虑屏幕尺寸显示Django网站

django - 为什么 django 中的 Simple 标签不起作用?

javascript - Django 渲染一个 "in exception"的页面而不是一个可以帮助调试的页面

python - 如何有效地计算两个字典的内积

python - 无法使用 Python 打开 Unicode URL

django - 瞬时使用 Django 模型实例

javascript - 如何使用 axios 向 django 发送空对象(图像)

python - 是否有等效于 python 字符串乘法函数的 django 模板?