How to Separate Frontend and Backend in Django

djangoweb-applications

I am evaluating frameworks and I would like to understand Django's architecture better.

Coming form a Java background I developed components separately namely front and backend. More concretely for my backend I use Dropwizard and start a HTTP server. For the front end I use a nginx webserver with some forwarding to connected to my backend api via REST with Json objects. The front end is just plain html and a little JavaScript in vue.js.

Now I have been reading about Django's Model-Template-View concept. with a single page application and JavaScript a Web app can be deployed and so a separation of backend and frontend is given.

To my understanding this is a little to sparse. Could some please clarify? And could you develop in Django so that the front end is independent from the backend? and if yes using the stack above could you give some hints how this is accomplished?

Best Answer

Simply said: It is designed not to be separated, but you can.

Frameworks like Django (Python) or Symfony (PHP) are designed to handle both frontend and backend in one application.
This means that a request comes in, the backend tasks are executed and a template is used to generated the corresponding HTML response. This does mean that all information needs to be gathered and put into html in a single request.

This is a great way of developing for (small) applications with relatively small amounts of data (handling) per view.

It is however completely possible to separate your frontend and backend.
This is most commonly done by making your backend (django in your case) a rest(ful) json api.
And using a JavaScript frontend using something like vue.js as you already have in your current setup.

While I do not have experience with it I would recommend the Django REST framework website for more information For Symfony development I would recommend FOSRestBundle.

Related Topic