要么我睡眠不足,要么我错过了一些明显的东西。
无论我做什么,我都无法在HttpResponseRedirect之后从基于类的视图中显示消息。
以下是我的观点:
class Add(SuccessMessageMixin, LoginRequiredMixin, CreateView):
template_name = "apps/add.html"
form_class = forms.Add
success_message = "Report was added successfully"
def form_valid(self, form):
team = get_object_or_404(t_models.Team, owner=self.request.user)
self.object = form.save(commit=False)
self.object.team = team
self.object.recorded_by = self.request.user
self.object.save()
form.save_m2m()
return HttpResponseRedirect(self.get_success_url())
def get_success_url(self):
return reverse('thing_detail', kwargs={'pk': self.object.id})
到目前为止,我已经仔细检查过所有会话设置是否正确,所有消息设置正确,我重新启动了VE并刷新了缓存。
有什么建议吗?
答案 0 :(得分:0)
尝试将mixins重新排序为Add(LoginRequiredMixin, SuccessMessageMixin, CreateView):