170 cards
Django is a high-level Python web framework designed for rapid development and clean, pragmatic design. It follows the Model-Template-View (MTV) architectural pattern, which separates concerns by placing data structure in Models, presentation logic in Templates, and business logic in Views. Django ships with many built...
Django models are Python classes that subclass django.db.models.Model, with each model mapping to a single database table and each class attribute representing a database column. The framework provides a rich set of field types to handle different kinds of data: CharField for short text requiring a max_length, TextFiel...
The Django ORM lets developers interact with the database using Python code rather than raw SQL. The default manager on every model is objects, and the all() method returns a QuerySet containing all rows in the table. To narrow results, filter() returns a QuerySet of zero or more objects, while get() returns a single o...
Django views are Python callables that take an HttpRequest and return an HttpResponse. Function-based views (FBVs) are simple Python functions, while class-based views (CBVs) subclass django.views.View and map HTTP methods to class methods like get() and post(). The CBV is registered in URL configuration by calling its...
Django's template engine uses HTML files with special syntax to separate presentation from logic. Variables are output using double curly braces like {{ variable }}, template tags use curly-brace percent syntax like {% tag %} for control flow, and filters transform values using the pipe syntax like {{ value|filter }}....
Django forms handle HTML form rendering, validation, and data cleaning through Python classes. A form is defined by subclassing forms.Form and declaring fields like CharField and EmailField. The form.is_valid() method triggers validation, and form.cleaned_data provides access to the validated, converted data. A ModelFo...
Middleware in Django is a framework of hooks that processes requests and responses globally. Each middleware is added to the MIDDLEWARE setting in settings.py and is executed in order for requests, then in reverse order for responses. Built-in middleware classes include SecurityMiddleware for HTTPS redirects and HSTS h...
Django REST Framework (DRF) is a powerful toolkit for building Web APIs on top of Django. Its key components include Serializers for converting models to and from JSON, ViewSets for grouping related API views, Routers for auto-generating URL patterns, multiple authentication options including token, session, and JWT, a...