A single-page application (SPA) puts interface rendering and much of the application logic in the browser. Rather than receiving a newly composed HTML page for each interaction, the browser downloads a JavaScript application that maintains a dynamic interface within one web page. section 1.2.1 section 11.1
The key distinction is where HTML is composed. Server-side rendering has the server assemble HTML with templates and send the result to the browser. An SPA sends browser code plus data; the browser creates and updates the interface. The browser still displays HTML either way—this is a division of responsibility, not a contest for who gets to use HTML. section 1.2.1
An SPA commonly divides work this way:
- The browser downloads a JavaScript bundle containing the user interface and substantial business logic. section 1.2.1
- The browser performs further user-interface interactions in place instead of navigating to separately generated pages. section 11.1
- The backend provides data and performs server-side work, often through an API that returns JSON. section 1.2.1
- Django views can serve API data rather than render HTML, with Django REST Framework or Django Ninja helping serialize ORM objects for JavaScript clients. section 1.2.1
An SPA is a design approach rather than a project type. Django can supply its backend while a browser frontend handles the GUI; the same API-oriented backend can also support mobile applications or other systems. A project can mix conventional web pages, APIs, and selective JavaScript interactivity rather than choosing a pure SPA everywhere. section 1.2.2 section 1.2.3 section 11.1
A JavaScript frontend with a Django API
React and Angular use the SPA mechanism: a JavaScript interface is downloaded once and then interacts with a backend API. Django can provide that API, while frameworks such as Django Ninja or Django REST Framework can make API creation quicker. Vue.js can also be used selectively on regular pages when a full SPA would be more machinery than the interaction needs. section 11.1 section 1.2.1 section 11.1
Figure 11.1 Mixing web and API interfaces allows Django to be a backend for multiple types of devices
Compare the possible frontend and API arrangements: Django can back web interfaces, mobile clients, and SPA-style browser interfaces at the same time. section 11.1




