我正在使用 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/