Master Django Framework with 50 free flashcards. Study using spaced repetition and focus mode for effective learning in Programming.
Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. It follows the MTV (Model-Template-View) architectural pattern and includes built-in features like an ORM, admin interface, and authentication system.
MTV stands for Model-Template-View:
Model – defines data structure and database schemaTemplate – handles the presentation layer (HTML)View – contains business logic and returns responses
Use the command:django-admin startproject myproject
This generates the project directory with settings.py, urls.py, wsgi.py, asgi.py, and manage.py.
Run:python manage.py startapp myapp
Then add 'myapp' to the INSTALLED_APPS list in settings.py to register it with the project.
A Django model is a Python class that subclasses django.db.models.Model. Each model maps to a single database table, and each attribute represents a database column. Example:class Article(models.Model):
title = models.CharField(max_length=200)
Common field types include:CharField – short text (requires max_length)TextField – long textIntegerField – integersBooleanField – True/FalseDateTimeField – date and timeForeignKey – many-to-one relationshipManyToManyField – many-to-many relationship
The Object-Relational Mapper (ORM) lets you interact with the database using Python code instead of raw SQL. You use model classes and querysets like MyModel.objects.filter(active=True) to query, create, update, and delete records.
Use the all() method on the model's manager:all_articles = Article.objects.all()
This returns a QuerySet containing all rows in the corresponding table.
Use filter() and exclude():Article.objects.filter(status='published')Article.objects.exclude(status='draft')
You can chain lookups like title__icontains='django', date__gte=some_date, and author__name='Alice'.
filter() returns a QuerySet (zero or more objects), while get() returns a single object or raises exceptions:DoesNotExist – if no match is foundMultipleObjectsReturned – if more than one match exists
Migrations are version-controlled changes to your database schema. Key commands:python manage.py makemigrations – creates migration files from model changespython manage.py migrate – applies migrations to the database
They are stored as Python files in each app's migrations/ directory.
Specify the migration name to revert to:python manage.py migrate myapp 0003_previous
To undo all migrations for an app:python manage.py migrate myapp zero
Flashcards
Flip to reveal
Focus Mode
Spaced repetition
Multiple Choice
Test your knowledge
Type Answer
Active recall
Learn Mode
Multi-round mastery
Match Game
Memory challenge