What are dunder methods?
Simple meaning
Dunder methods, also called magic methods, are special names with double underscores such as __init__ and __str__.
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.
Dunder methods, also called magic methods, are special names with double underscores such as __init__ and __str__.
Open the full page for Why, Steps, Example and Key takeaway.
__str__ returns the informal string used by str() and print().
Open the full page for Why, Steps, Example and Key takeaway.
__len__ is called by len() and should return a non-negative int.
Open the full page for Why, Steps, Example and Key takeaway.
__eq__ implements == for your class.
Open the full page for Why, Steps, Example and Key takeaway.
unittest is the standard library's xUnit-style test framework.
Open the full page for Why, Steps, Example and Key takeaway.
pytest is a third-party runner with plain assert, fixtures, and rich plugins.
Open the full page for Why, Steps, Example and Key takeaway.
django.test.TestCase wraps each test in a database transaction that is rolled back.
Open the full page for Why, Steps, Example and Key takeaway.
View tests catch broken URLs, auth, status codes, and template context before production.
Open the full page for Why, Steps, Example and Key takeaway.
Middleware is a hook that runs on every request and response.
Open the full page for Why, Steps, Example and Key takeaway.
The MIDDLEWARE list in settings.py is an ordered sequence of dotted class paths.
Open the full page for Why, Steps, Example and Key takeaway.
SecurityMiddleware sets HTTPS redirects and security headers such as HSTS.
Open the full page for Why, Steps, Example and Key takeaway.
Signals are a dispatcher that lets decoupled apps react to events such as a model save.
Open the full page for Why, Steps, Example and Key takeaway.
post_save runs after a model is saved to the database.
Open the full page for Why, Steps, Example and Key takeaway.
Decorate a function with @receiver(post_save, sender=MyModel) or call post_save.connect(handler, sender=MyModel).
Open the full page for Why, Steps, Example and Key takeaway.
DRF is a toolkit for building Web APIs on top of Django.
Open the full page for Why, Steps, Example and Key takeaway.
A serializer converts model instances or primitives to JSON-like data and validates incoming payloads.
Open the full page for Why, Steps, Example and Key takeaway.
APIView is DRF's base class-based view.
Open the full page for Why, Steps, Example and Key takeaway.
@api_view turns a function into a DRF function-based view and lists allowed methods.
Open the full page for Why, Steps, Example and Key takeaway.
Caching stores expensive query or render results so later requests skip the work.
Open the full page for Why, Steps, Example and Key takeaway.
django.core.cache.cache.set(key, value, timeout) stores a pickled value in the configured backend.
Open the full page for Why, Steps, Example and Key takeaway.