我无法获得清晰的表格,并且django的DeleteView内置功能无法协同工作。如果我从模板中删除了松脆的逻辑,则删除工作正常。带有松脆形式的添加和更新逻辑以及分别内置于CreateView和UpdateView的django也可以正常工作-只是删除失败。我知道这看起来与其他问题相似,但我不认为这是重复的问题-这些问题不使用DeleteView也不适用他们的答案(再次,我的看法是……不当然)。
错误是:/ EventSubType / 12 / delete /
处的VariableDoesNotExist在[{'False':False,'None':None,'True':True},{},{},{'eventsubtype':,'view':,'对象':}]
models.py
class EventSubType(models.Model):
subtype = models.CharField(max_length=25,)
event_type = models.ForeignKey('EventType', on_delete=models.PROTECT)
description = models.CharField(max_length=1000, null=True, blank=True)
def __str__(self):
return str(self.subtype)
def get_absolute_url(self):
return reverse('eventsubtype_edit', kwargs={'pk': self.pk})
views.py
class EventSubTypeDelete(LoginRequiredMixin, PermissionRequiredMixin, DeleteView):
permission_required = "<snip>.delete_eventsubtype"
model = EventSubType
form_class = EventSubTypeDeleteForm
success_url = reverse_lazy('eventsubtype_list')
forms.py
class EventSubTypeDeleteForm(forms.ModelForm):
class Meta:
model = EventSubType
fields = ['subtype',]
def __init__(self, *args, **kwargs):
super(EventSubTypeDeleteForm, self).__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.layout.append(Submit('save', 'Delete'))
template
{% extends "base.html" %}
{% load crispy_forms_tags %}
{% block content %}
<h1>Event Sub Type Delete</h1>
{% crispy form %}
{% endblock %}