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?
-
stackoverflow.com/questions/9081123Robert Harvey– Robert Harvey06/25/2018 18:17:57Commented Jun 25, 2018 at 18:17
1 Answer 1
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.
-
First of all thank you for your answer. This is what I suspected when reading other post which were less concrete as you. So I guess this means that I would only swap my Java(Dropwizard) backend with a Python(Django) backend and all of my front end would just stay the same. However It seems that the Django community and the documention seems to be more detailed.A.Dumas– A.Dumas11/27/2017 13:38:14Commented Nov 27, 2017 at 13:38
-
Yup, you should be able to just switch your backend around and your frontend should keep working just fine. (Given that you replicate all the functionality you have in your current backend of course)HTDutchy– HTDutchy11/27/2017 15:30:16Commented Nov 27, 2017 at 15:30
-
1You may not even need Django REST Framework, Django comes with JsonResponse out of the box. Meaning making a RESTful application is just a matter of programming it be so.Tich– Tich11/28/2017 10:20:40Commented Nov 28, 2017 at 10:20