ValueError-未返回HttpResponse对象。 -在删除视图Django中

时间:2019-03-13 10:13:41

标签: django django-models django-forms django-templates django-views

我在删除用户时得到apply plugin: 'com.android.application' android { compileSdkVersion 28 defaultConfig { applicationId "ApplicationId" minSdkVersion 19 targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } }

错误-

  

Valueemp at / employee / delete / 31 /

     

视图apps.employee.views.EmployeeDeleteView没有返回HttpResponse   宾语。它返回None。

ValueError

这是错误的回溯

class EmployeeDeleteView(LoginRequiredMixin, generic.DeleteView):
    model = User
    template_name = 'employee/employee_confirm_delete.html'
    context_object_name='employees'

    def get(self, request, *args, **kwargs):
        # Tab Opts Checking
        if request.user.userprofile.user_company.company_tab_opts:
            return redirect('admin_employee')

    def delete(self, request, *args, **kwargs):
        self.object = self.get_object()
        self.object.userprofile.soft_delete()
        messages.success(request, 'Employee Deleted Successfully.')
        return HttpResponseRedirect(reverse('admin_employee'))

1 个答案:

答案 0 :(得分:0)

这就是我所做的。但是不知道这是正确的方法

class EmployeeDeleteView(LoginRequiredMixin, generic.DeleteView):
    model = User
    template_name = 'employee/employee_confirm_delete.html'
    context_object_name='employees'


    def delete(self, request, *args, **kwargs):
        # Tab Opts Checking
        if request.user.userprofile.user_company.company_tab_opts:
            return redirect('admin_employee')
        self.object = self.get_object()
        self.object.userprofile.soft_delete()
        messages.success(request, 'Employee Deleted Successfully.')
        return HttpResponseRedirect(reverse('admin_employee'))