Django Admin的“删除确认”页面上的删除按钮不起作用
Posted
技术标签:
【中文标题】Django Admin的“删除确认”页面上的删除按钮不起作用【英文标题】:Delete Button on "Delete Confirmation" Page of Django Admin Is not Working 【发布时间】:2016-09-21 20:27:14 【问题描述】:这是我的模板路径
project/templates/app_name/delete_confirmation.html
% extends "admin/base_site.html" %
% load i18n admin_urls %
% block content %
% if perms_lacking %
<p>% blocktrans with escaped_object=object %Deleting the object_name ' escaped_object ' would result in deleting related objects, but your account doesn't have permission to delete the following types of objects:% endblocktrans %</p>
<ul>
% for obj in perms_lacking %
<li> obj </li>
% endfor %
</ul>
% elif protected %
<p>% blocktrans with escaped_object=object %Deleting the object_name ' escaped_object ' would require deleting the following protected related objects:% endblocktrans %</p>
<ul>
% for obj in protected %
<li> obj </li>
% endfor %
</ul>
% else %
<p>% blocktrans with escaped_object=object %Are you sure you want to delete the object_name " escaped_object "? All of the following related items will be deleted:% endblocktrans %</p>
% include "admin/includes/object_delete_summary.html" %
<h2>% trans "Objects" %</h2>
<ul> deleted_objects|unordered_list </ul>
<form action="" method="post">% csrf_token %
<div>
<input type="hidden" name="post" value="yes" />
% if is_popup %<input type="hidden" name=" is_popup_var " value="1" />% endif %
% if to_field %<input type="hidden" name=" to_field_var " value=" to_field " />% endif %
<input type="submit" value="% trans "Yes, I'm sure" %" />
<a href="#" onclick="window.history.back(); return false;" class="button cancel-link">% trans "No, take me back" %</a>
</div>
</form>
<input type="submit" value="% trans "Cancel" %" onclick="window.history.back(); return false;"/>
% endif %
% endblock %
我在这里尝试继承 django-admin 的 delete_confirmation.html
模板。我想在删除应用程序中的对象时添加一个cancel
按钮。它向我显示了取消按钮,它也可以正常工作,但 delete
按钮不会这样做。
我尝试在“管理模板”中定义的“本地模板”中添加链接,但它引发了“找不到反向 url”的错误。有什么解决方法可以做到这一点吗?请建议我正确的方法。
提前致谢。
【问题讨论】:
很好的回答如何覆盖删除确认页面:***.com/questions/17440732/… 这能回答你的问题吗? how to override delete confirmation page in django admin site? 【参考方案1】:不要继承 django-admin 的 delete-confirmation.html 模板,而是将模板从 django/contrib/admin/templates/admin/delete_confirmation.html 复制到您的项目目录中并在其中自行进行更改。
【讨论】:
以上是关于Django Admin的“删除确认”页面上的删除按钮不起作用的主要内容,如果未能解决你的问题,请参考以下文章