Django call a class based view from another class based view

Viewed 130

I have two classes corresponding to two different forms. When one is submitted, i need to call the other one.

class FormsPreInput(CreateView):
    template_name = "form_preinput.html"

    def get(self, request, *args, **kwargs):
        form = preinput_form()
        return render(request, self.template_name, {"form": form})

    def post(self, request, *args, **kwargs):
        form = preinput_form(request.POST)
        if form.is_valid():
            return FormsInput.as_view()(request=self.request)

class FormsInput(CreateView):
    template_name = "input_form.html"

    def get(self, request, *args, **kwargs):
        print("inside input get")
    def post(self, request, *args, **kwargs):
        print("inside post ")

So the problem is the code is FormsInput is being called using the POST request object, so the code goes to FormsInput.post() without going to FormsInput.get()

0 Answers
Related