Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backend and frontend MVC

I am very new to the world of web development and MVC architectures. I am currently working on django which i believe is an MVC framework. if i am right, for a web application MVC implies

views is the front end models is the backend controllers are the glue between frontend and backend

well if the above is true and views are the only frontend parts what exactly is the function of frontend frameworks like backbone, angular? how exactly do they deploy the mvc concept? Also when building a simple blogging site which framework would be preferrable? and also are there instances of websites working on both frontend and backend mvc frameworks? please give examples. for clarification i went through this question: In the Model-View-Controller principle, what is the Frontend and what is the Backend? but couldnt understand fully. thank you

like image 789
user2627317 Avatar asked Aug 02 '13 17:08

user2627317


1 Answers

There is no one-on-one analogy of front- and backend and the MVC model. For example, the admin of a (Django) site is generally considered to be part of the backend - it is not the part of the site the user will see - but part of the admin is definitely the View part of the MVC model. Anything a normal web user sees and/or directly interacts with is part of the frontend, everything else is part of the backend.

Now what is the MVC framework used in Django? We have:

  • The Model: this is the part of the application that holds the state of the application. In Django, a big part of this is the database and it's abstraction layer, the Django models. Other parts are user sessions and the request variable.
  • The View: this is the part of the application that presents the state of the application to the user. Django views and templates are responsible for this. Any data you see when you open up the website is the View part of MVC. The overall presentation is also part of this.
  • The Controller: this is the part of the application that represents any action you, the user, takes. Django is not truly a separated MVC framework because the View part and the Controller part are so tightly interwoven: any link, form or button you see on the site is a controller. It tells the site to do an action, such as present a different view (e.g. a link), or change the state of the model (e.g. an edit form).

What about Backbone or Angular? Why do you need two different MVC frameworks in a single application?

Django is a server-side framework. Every action happens on the server. If you click a link or submit a form, you send a request to the server and the server sends back a complete, static response (static in the sense that the page doesn't change once it's in your browser). You can't use Django to use logic client-side, as it is a python framework that runs on your server, not in your client's browser. Instead, it's Javascript's job to add any client-side logic, e.g. to reorder a list of items on the page or to dynamically add a new one. Now each page can be seen as some kind of mini-application.

Backbone and Angular are examples of MVC frameworks for such client-side applications. It supplies the client-side application logic that a server-side framework such as Django lacks, and surprisingly the people who like an MVC framework to develop a server-side application generally also like to use an MVC framework to develop a client-side application.

like image 162
knbk Avatar answered Sep 25 '22 08:09

knbk