I am a beginner in web development, I have a server in flask that is hosted on pythonanywhere. I brought up the MySQL server, set up its operation with flask, but there is such a problem: I need to load it when I go to the tab, and the data in the database are recorded in parallel, how can this be implemented?

  • one
    I think something like this: when you click on a tab, you will need to send ajax request to the server and display it on the progressbar page (for example, the GIF), while the server processes the request, the progressbar will spin as the answer comes from the server, you need to display it on the tab and remove the progressbar. For convenience, you can use jquery with its ajax method (the method has all sorts of useful oncomplete ) - gil9red

1 answer 1

Flaks is a web framework. It is important for a novice developer to understand two important facts about web development:

  1. Any web application actually consists of two applications written in different languages, running on different machines and at different times - frontend and backend 1 .
  2. The frontend and backend exchange data via the HTTP protocol , and this is a protocol without state 2 operating in the request-response mode. This means that the front and back have no permanent connection. The moment you see a page in the browser, the code that generated it on the server has long been completed.

Of these two factors, there are many differences in the development of web applications from any other development. For example, long-running tasks should not be executed in request handlers 3 , and the logic of user interaction should not imply waiting for something.

Of course, there are ways to smooth out these features - AJAX , SSE , Websockets, and more. For example, web sockets allow the front and back to exchange data in real time. They are well suited for your task. But Flask is not suitable for web sockets, they need some asynchronous framework 4 .


  1. Sometimes the frontend is a full-fledged application with logic, and sometimes reduced to a primitive html-interface.
  2. Well, in the original basis. There are crutches that fix this inconvenience - Cookie . But all the same, it is important to know about this restriction and it is important to take it into account in order to create good web applications.
  3. They should be shifted to background services such as Celery .
  4. For example aiohttp .
  • Kst, at flask saw socketio: github.com/miguelgrinberg/Flask-SocketIO - gil9red
  • @ gil9red did not look into his code, but he spent a lot of time in Flask code, and there almost every line is built on the assumption that the code works synchronously. Therefore, I am somewhat alarmed by the attempts of its asynchronous application. However, even more synchronous Django managed to get on Daphne with the help of Channels, maybe this is also well done. - Sergey Gornostaev