P
P
polger2021-01-31 11:56:29
React
polger, 2021-01-31 11:56:29

Why does working with files in a Django view cause a React page reload?

On the backend I use Django + DRF. I start the server with the command python3 manage.py runserver
Ubuntu 20.04.1 LTS
On the React 17.0.1 front I
send a POST request to the server using axios. On the server in the view, the following code is the simplest:

fd = open(pathFile, 'xb')
fd.close()
return Response(anyData)

I note that initially there is no file in the directory. When the code is executed, it is created empty as it should be. But it is at the moment of working out the open function that the page is reloaded in the browser, as if F5 was pressed.

My second observation.
If use:
fd = open(pathFile, 'wb')
fd.write(binaryData)
fd.close()
return Response(anyData)

If there is no file in the directory, then the code is processed as it should, the file is created with the content and the page is not reloaded. But if the file already exists, then the page is reloaded, but the contents of the file are overwritten. In other words, the view is processed completely.
There are no exceptions or errors.
I also tried these manipulations through os.open. The behavior is similar.
I can't understand why this is happening. Maybe the server at the time of working with files sends some headers to the front on which the page is reloaded? But how then to track them in the browser if the page is reloaded. How to diagnose a problem? Or is there a ready solution?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2021-01-31
@bacon

And what about the server? Understand the logic of how React works.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question