Backend and MVC Interface

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 environment. if I am right, for a web application MVC is implied

views - this is the interface of the model - this is the backend controllers - this is the glue between the interface and the backend

Well, if this is true, and views are the only components of the interface, what exactly is a function of frontend frameworks such as trunk, angular? How exactly do they deploy the mvc concept? Also when creating a simple blog site, which would be preferable? and also there are sites working both on external, and on mvc backend systems? Give examples. for clarification, I examined this question: In principle, Model-View-Controller, what is Frontend and what is Backend? but cannot fully understand. thanks

+4
source share
3 answers

There are no analogs to the analog front and backend and the MVC model. For example, a site administrator (Django) is generally considered part of the backend - it is not part of the site that the user sees, but part of the administrator is a specific part of the MVC model. Everything that a regular web user sees and / or interacts directly with is part of the interface, everything else is part of the backend.

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

  • Model: This is the part of the application that contains the state of the application. In Django, most of this is a database and an abstraction layer - Django models. Other parts are user sessions and the request variable.
  • View: This is the part of the application that represents the state of the application to the user. The views and patterns of Django are responsible for this. Any data that you see when you open the website is part of the MVC view. A general presentation is also part of this.
  • Controller: this is part of the application that represents any action that you, the user, takes. Django is not really a shared MVC environment, because the View part and the Controller part are so closely intertwined: any link, form or button that you see on the site is a controller. It tells the site to perform an action, for example, to present another view (for example, a link) or to change the state of the model (for example, an editing form).

What is Backbone or Angular? Why do you need two different MVC frameworks in one application?

Django is a server environment. Each action takes place on the server. If you click on the link or submit the form, you will send a request to the server and the server will send a full static response (static in the sense that the page will not change after viewing it in your browser). You cannot use Django to use the logical client side, since it is a python framework that runs on your server, and not in your client browser. Instead, it is a Javascript job to add any client logic, for example. reorder the list of items on the page or dynamically add a new one. Now each page can be seen as a kind of mini-application.

Backbone and Angular are examples of MVC frameworks for such client applications. It delivers client-side application logic, which is not server-side like Django, and, surprisingly, people who like the MVC environment for developing a server application usually also like to use the MVC environment for developing a client application.

+8
source

Django is a kind of hybrid version of the Model-View-Controller. Django documentation usually describes it as a Model-View-Template. Typically, a template (Django HTML with template tags, etc.) is usually mapped to a regular view, giving the user a view on web pages. A view in Django usually replaces a controller because it works between the Model, taking data from databases and defining new objects, and the view, which in this case is a Template. The model is similar to normal in Django, providing definition for different objects. Therefore, although Model-View-Controller is usually a model for most languages, it is rather a Model-View-Template model, and the view is different from the usual one. See below for more details:

http://jeffcroft.com/blog/2007/jan/11/django-and-mtv/

0
source

I am considering Django and web development templates.

What I prefer at the moment (2014-01) is.

Use Django (restful / json) as MC, model / controller or backup data and logic. Part of the controller in Django relates to business rules and access control.

then use javascript framework and html bit as client side code. View / Controller.

In practice, the client / browser loads the javascript program, View / controller, which then performs soothing queries on the supported model / controller

0
source

Source: https://habr.com/ru/post/1495008/


All Articles