我正在使用 Django Framework 在 Python 中编写应用程序,我试图弄清楚是否有可能为特定模块修改现有的 Django 管理应用程序模板(change_form.html、base_site.html ...)。在文件夹项目中,我已经将 templates/admin 目录放在我修改管理应用程序模板的地方,但是对于一个特定的模块,我想使用不同的模板。特定模块位于单独的应用程序中。
如果您能让我知道如何实现这一点,或者至少指出我可以找到它的文档,我将不胜感激。
非常感谢您。
请您参考如下方法:
您可以通过在您希望自定义的级别覆盖特定模板来完成此操作。例如,如果您想为您的应用修改 change_form.html,您可以在 templates/admin/中创建(或从 contrib/admin/templates 复制 change_form.html...)模板你的应用程序/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.
