I develop a Class Based View to render a list of elements that you can see below:
class ConfirmBeforeRunTest(LoginRequiredMixinRedirect,ListView):
template_name = "app_testing_house/confirm_before_run.html"
# Redirect to login page if not auth
redirect_unauthenticated_users = True
# Options for ListView
model = Test
context_object_name = 'test_list'
def get_queryset(self):
return Test.objects.filter()
def post(self, request, *args, **kwargs):
return TestToRunPostProcessorView.as_view(request)
As you can see, I want to be able to handle POST request processing in my view in order get some arguments for my queryset. I once read a blog saying that one CBV = one function. So i created an other view, to handle all the POST process:
class TestToRunPostProcessorView(FormView):
form_class = TestToRunForm
def form_valid(self, form):
# Process form
return self.render_to_response(context)
def form_invalid(self, form):
return self.render_to_response(self.get_context_data(form=form))
Unfortunately it doesn't work and I get the following error message:
as_view() takes exactly 1 argument (2 given)
So I assume return TestToRunPostProcessorView.as_view(request)
is not correct but I don't know why..