MVC & MTV Frameworks Flashcards
What are routes?
Routing is handled by a separate document that contains a list of available routes and calls to the appropriate view functions. When a request is received routing identifies the view method to be called.
What are view functions?
view functions generally:
Redirect to other routes
Render specific templates
Invoke methods attached to other pieces of our app that we characterize as models
What are models?
It is likely that the views file will call some model method in order to perform some operation on the database. Models should do the following:
Build database tables
Handle logic related to database operations, including validation
What are templates?
a view function will either render a template or redirect. When a template is rendered Django has to parse the file looking for logic or variables you’ve inserted, interpret those, before sending a complete HTML document as a response to the client. Django templates are so similar to Flask (Jinja2) templates that you’ll hardly notice a difference.
What does MTV stand for?
MTV stands for ‘model template view’, which describes the division of labor in Django.
What does MVC stand for?
Models, Views and Controller
although Django’s terminology varies slightly from the usual MVC pattern, the two are close enough that Django may be considered an MVC framework. Although it is important to use the right term for each component, we can think of Django as an MVC framework.
What does Controller mean?
The MVC controller is roughly equivalent to Django’s views. In both framework types this component should be in charge of outsourcing work to the models and sending the appropriately formatted data to the client. We mentioned that some other frameworks don’t outsource logic to the model. In those cases, many of our logical operations are done in the controller.
Define Object-Relational-Mapper (ORM)
Django uses an Object-Relational-Mapper (ORM) to map Model definitions in the Django code to the data structure used by the underlying database. As we change our model definitions, Django tracks the changes and can create database migration scripts (in /locallibrary/catalog/migrations/) to automatically migrate the underlying data structure in the database to match the model.
What is settings.py?
contains all the website settings. This is where we register any applications we create, the location of our static files, database configuration details, etc.
What is urls.py
defines the site url-to-view mappings. While this could contain all the url mapping code, it is more common to delegate some of the mapping to particular applications
What is wsgi.py
py is used to help your Django application communicate with the web server. You can treat this as boilerplate.
What is manage.py?
The script is used to create applications, work with databases, and start the development web server.
What is the migrations folder used for?
used to store “migrations” — files that allow you to automatically update your database as you modify your models.
What is the __init__.py file?
an empty file created here so that Django/Python will recognise the folder as a Python Package and allow you to use its objects within other parts of the project.
What is request.POST?
Data from POST request