Django Reference
Free reference guide: Django Reference
About Django Reference
The Django Reference is a searchable cheat sheet covering the core building blocks of the Django web framework. It spans six key areas: Models (ORM field types, ForeignKey, ManyToManyField, QuerySet methods like filter, get, create, and Q objects for complex lookups), Views (HttpResponse, render, redirect, class-based views such as ListView, and the @login_required decorator), and Templates (variable output, template tags, {% for %} loops, {% extends %}/{% block %} inheritance, and built-in filters). Each entry pairs a syntax name with a concise description and a real, runnable Python code example.
Backend developers, full-stack engineers, and Django bootcamp students are the primary users of this reference. It is especially handy during code review, when you need to recall the exact signature of objects.filter() versus objects.get(), or when you want to double-check how {% extends %} and {% block %} interact in template inheritance. The reference also covers URL routing with path() and include(), form validation with forms.Form and ModelForm, and authentication helpers like authenticate(), UserCreationForm, and @permission_required.
Entries are grouped into six categories — Models, Views, Templates, URL, Forms, and Auth — so you can filter down to exactly the section you need without scrolling through unrelated syntax. The tool runs entirely in your browser with no backend calls, meaning every search and category filter is instant. Both Korean and English interfaces are available, and the layout adapts to dark mode and any screen size.
Key Features
- ORM coverage: filter(), get(), create(), Q objects, ForeignKey, ManyToManyField with real Python examples
- View layer: HttpResponse, render(), redirect(), ListView, and @login_required decorator patterns
- Template engine: {{ variable }}, {% if %}, {% for %}, {% extends %}/{% block %}, and {{ value|filter }} syntax
- URL routing: path(), include(), reverse(), and named URL patterns with int/str converters
- Forms: forms.Form field definitions, ModelForm with Meta class, and form.is_valid() validation flow
- Authentication: authenticate(), login(), UserCreationForm, and @permission_required decorator
- Six filterable categories (Models, Views, Templates, URL, Forms, Auth) for targeted lookup
- Instant in-browser search across syntax names and descriptions — no server round-trip
Frequently Asked Questions
What is the difference between objects.filter() and objects.get()?
objects.filter() returns a QuerySet that can contain zero or more objects and supports chaining. objects.get() returns exactly one object and raises DoesNotExist if not found or MultipleObjectsReturned if more than one matches. Use get() when you expect a unique result (e.g., by primary key) and filter() for conditional queries.
When should I use a class-based view instead of a function-based view?
Class-based views (CBVs) like ListView or DetailView are best when you need Django's generic functionality — pagination, object retrieval by pk, or form handling — without writing boilerplate. Function-based views are simpler for custom logic that doesn't map well to a generic pattern. Both approaches are valid and can coexist in the same project.
How does template inheritance work with {% extends %} and {% block %}?
A child template starts with {% extends "base.html" %} to inherit the parent layout. It then overrides named {% block content %}...{% endblock %} sections. The parent renders all blocks that the child does not override with their default content. This avoids duplicating headers, footers, and navigation across every page.
What is the Q object used for in Django ORM?
Q objects let you build complex query conditions using | (OR) and & (AND) operators that cannot be expressed with plain keyword arguments. For example, Post.objects.filter(Q(title__contains="django") | Q(title__contains="python")) returns posts whose title contains either word.
What is the difference between forms.Form and ModelForm?
forms.Form requires you to define every field manually and handle saving yourself. ModelForm auto-generates fields from a model class specified in the Meta.model attribute, and its save() method creates or updates the corresponding database row. Use ModelForm when your form maps directly to a model; use Form for custom or multi-model forms.
How does @login_required differ from @permission_required?
@login_required redirects anonymous users to the login page. @permission_required additionally checks that the authenticated user holds a specific permission string (e.g., "blog.add_post") and raises PermissionDenied (or redirects) if they do not. Use @permission_required when role-based access control is needed beyond just being logged in.
How does reverse() work in Django URL routing?
reverse('url-name', kwargs={'pk': 1}) generates the URL string for a named URL pattern at runtime. This avoids hardcoding paths and automatically reflects any URL changes in urls.py. It is the programmatic equivalent of the {% url 'url-name' pk=1 %} template tag.
Can I use this reference offline?
Yes. After the page loads, all reference data is stored in your browser. You can use the search and filter functionality without an internet connection because no network requests are made during normal use.