我使用的模型类的方法来显示修改列表表单上的按钮。我有一个非常奇怪的问题,只有第一个按钮不起作用。即使我有两个单独的按钮方法,那么左边的第一行将不起作用。 我检查出页面的源代码和错误是Django管理使用按钮
Saw a form start tag but there was already an active form element. Nested tags are not allowed. Ignoring the tag.
在进一步的检查,我发现
<form id="grp-changelist-form" action="" method="post"><input type='hidden' name='csrfmiddlewaretoken' value='l6Z2ez9F00XMVQjp0KIRIKgRIcQ9nnQc' />
这种形式是开放的。 任何建议来解决这个问题。 培训相关码是
Class MyModel(models.Model):
.
.
def method1(self):
return '<form action="path/to/action1" method="get"><input type="submit" value="%s"></form>' % (self.id, label)
def method2(self):
return '<form action="path/to/action2" method="get"><input type="submit" value="%s"></form>' % (self.id, label)
然后使用上管理员的list_display的两种方法。 我正在使用Grappelli。
这听起来像你正试图呈现一个表单中的表单(你不能这样做:http://stackoverflow.com/questions/379610/can-you-nest-html-forms)。你在哪里插入/渲染表单代码? –