When should you prefer composition over inheritance?
Simple meaning
Use inheritance for true is-a relationships and shared polymorphic APIs.
Open the full page for Why, Steps, Example and Key takeaway.
Panel-ready Python & Django questions for freshers and experienced developers. Practice at Coding Cadre in Faridabad, or Online from Delhi NCR.
Use inheritance for true is-a relationships and shared polymorphic APIs.
Open the full page for Why, Steps, Example and Key takeaway.
The venv interpreter's sys.prefix points at the env directory, so imports look in venv/lib/site-packages first.
Open the full page for Why, Steps, Example and Key takeaway.
venv ships with Python 3 and is enough for most Django apps.
Open the full page for Why, Steps, Example and Key takeaway.
Editable install links the project into site-packages so code changes apply without reinstalling.
Open the full page for Why, Steps, Example and Key takeaway.
Specifiers such as >=, ~=, and == constrain acceptable versions on a requirement line.
Open the full page for Why, Steps, Example and Key takeaway.
The WSGI/ASGI handler loads middleware, resolves the URL, and calls the view.
Open the full page for Why, Steps, Example and Key takeaway.
Function-based views are clearer for one-off endpoints with simple branching.
Open the full page for Why, Steps, Example and Key takeaway.
A context processor is a function that receives the request and returns a dict merged into every template context.
Open the full page for Why, Steps, Example and Key takeaway.
A child template starts with {% extends 'base.html' %} and fills named {% block %} regions.
Open the full page for Why, Steps, Example and Key takeaway.
select_related performs a SQL join for forward ForeignKey and OneToOne relations and is a single query.
Open the full page for Why, Steps, Example and Key takeaway.
N+1 happens when you fetch a list, then access a related field per row, issuing one query plus N more.
Open the full page for Why, Steps, Example and Key takeaway.
F() references a field value in the database so updates happen in SQL, not in Python.
Open the full page for Why, Steps, Example and Key takeaway.
Q objects let you build complex WHERE clauses with | (OR), & (AND), and ~ (NOT).
Open the full page for Why, Steps, Example and Key takeaway.
Set db_index=True on a field, or declare indexes in Meta.indexes / unique_together / UniqueConstraint.
Open the full page for Why, Steps, Example and Key takeaway.
ForeignKey is many-to-one.
Open the full page for Why, Steps, Example and Key takeaway.
On the way in, Django runs middleware from top to bottom of the MIDDLEWARE list.
Open the full page for Why, Steps, Example and Key takeaway.
Legacy mixin-style middleware implemented process_request, process_view, process_exception, and process_response.
Open the full page for Why, Steps, Example and Key takeaway.
Define a class that takes get_response in __init__ and in __call__ runs pre-logic, calls get_response(request), then post-logic.
Open the full page for Why, Steps, Example and Key takeaway.
It should see the raw request early to apply SSL redirects and refuse bad hosts before other layers do work.
Open the full page for Why, Steps, Example and Key takeaway.
pre_save and pre_delete/post_delete wrap persistence.
Open the full page for Why, Steps, Example and Key takeaway.