How to continue to execute python code after responding to the client's request in the view?

To answer the direct question being asked in the title, you can’t. The response to the client’s request ends the view. To do otherwise requires an external handler like a celery task.

So in this case, I’d accept the data, validate it to the degree possible, call the celery task with that received data, and return the response. The celery task can take as long as necessary to actually process the data.