Django Flashcards
what is context variable lookup?
it’s a mechanism in django that allows us to insert variables in our templates. These variables are added to the context and rendered in the view.
How does DTL handle invalid variables?
returns an empty string.
what is reverse URL resolution in django?
it’s a way to get the absolute url, we can use either use the reverse( ) method or in the template url template tag, and in the model class get_absolute_url( ).
What is the functionality of django.contrib.auth app?
It’s a built-in Django application. It gives authentication and authorization functionality out of the box.
describe laziness in django.
The concept of laziness refers to when a function call is not immediately executed until its return value is accessed. The best example of this in Django is the querysets. The queryset object doesn’t actually make a call to the database until the queryset is evaluated. Laziness improves performance in our Django applications because we take fewer trips to the DB.
how does Django deal with static file optimization?
Django makes use of the ManifestStaticFileStorage to optimize static files. it does this by taking advantage of browser caching. when we collectstatic it appends an md5 hash of the contents of each static to its name. You can cache this file. on the browser it’s one less asset to load, we can also cache this for pages that still make reference to it.
What is ManifestStaticFileStorage and how does it work?
It is one of the ways Django optimizes static files. it stores the file name it handles by appending the md5 hash of the files content to the filename. ex css/styles.css would also be saved as css/55e7cbb9a48.css
what is the STATIC_ROOT setting in Django?
it’s the absolute path to the directory where we collectstatic files to be served.
What is the STATIC_URL setting in django?
It’s the url to use when referring to static files located in the static root.
What is the purpose of the ManifestStorageFile class?
It allows developers to serve old static files by pages that still reference them. it also helps with load time by taking advantage of the browser caching.
what is collectstatic?
collectstatic scans the directories in the setting STATICFILES_DIRS. All static files found are then
collected to the directory at STATIC_ROOT.
what is pagination?
Pagination is a way to split a large data set into smaller data subsets that you can iterate over the pages/subsets. The pages are provided as per user request. Advantage of pagination is improved performance, less bandwith and overhead for each request.
How do you implement pagination in django?
Use the Paginator class or module.
what are signals in django?
Signals is a mechanism in django that allows developers to communicate events between apps. There are many types of signals in django. The ones i am familiar with are the model based signals. ex pre_save, post_save, pre_delete etc.
What are some django signals?
Model signals: pre_save, post_sav, pre_delete.