python - 如何在 Django 管理表单中添加自定义操作按钮并发布信息

标签 python python-3.x django django-forms django-admin

enter image description here

我是 Django 新手!

我正在使用 Django 管理。我如何制作一个新按钮(靠近保存,...)并发布信息并在 python 脚本中使用它(我使用的是 Django 版本 2)。

管理员.py:

admin.site.register(Router)
admin.site.register(Peer, PeerModelAdmin)
admin.site.register(Prefixe, PrefixModelAdmin)

最佳答案

您需要覆盖 change_form_template。像这样尝试:

class YourModelAdmin(admin.ModelAdmin):
    change_form_template = 'custom_change_form.html'

custom_change_form.html 中,它应该从 admin/change_form.html 扩展,它可以是这样的:

{% load i18n %}
{% extends 'admin/change_form.html' %}
    <button> Your Custom Button </button>
    <input type="submit" value="{% trans 'Save' %}" class="default" name="_save">
{% endblock %}

关于python - 如何在 Django 管理表单中添加自定义操作按钮并发布信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53616273/

相关文章:

python - 如何用逗号分割 python 列表

python - 如何调用 pandas read_csv() 而不解析日期字符串

python - Django 测试 - 'HTTP_USER_AGENT' 测试客户端的关键字参数无效

python-3.x - 如何从xpath提取元素标签中不存在的字段?

Python,行迭代器

python - Django - 在 session 中存储对象是一个好习惯吗?

python - 将稀疏 scipy 矩阵加载到现有的 numpy 稠密矩阵中

python - 初学者 : Python can't find 'pyodbc' package?

java - 如何从 Python 启动 jBPM 流程?

python - Django:unique_together 是否以与 ForeignKey 相同的方式暗示 db_index=True?