[Fixed]-How can I send the result of the operation to the same template where the user submited the form using a django FormView?

1👍

You would have to go to a class based view, as such:

class MyView(View):

    def get(self, request):
        my_form = Formname()
        return render(request, 'template.html', {'my_form': my_form})

    def post(self, request):
        my_form = Formname(request.POST)
        if my_form.is_valid():
            result = do_stuff()
            return render(request, 'template.html', {'my_form': my_form, 'result': result})
        return render(request, 'template.html', {'my_form': my_form})

0👍

Create a new view where the user submits the form from the template and render the same template from that view including the submitted data.

Leave a comment