Glossary
164 terms from Django Basics, in plain words, each with the chapter that teaches it.
#
- @login_required
- A decorator that checks a visitor is logged in before the view runs. If they aren't, it sends them to the login page instead.
- __init__
- The special method Python runs when you create a new object from a class, such as `Bag("House Espresso", "16.00")`. It sets up the object's starting attributes.
- __str__
- A method that says what an object looks like as text. Kettle & Crane's `Product` returns its name, so the shell and admin show `House Espresso` instead of a vague object label.
- {% csrf_token %}
- A template tag that adds the hidden secret field Django needs to accept a POST form. Without it you get `Forbidden (403)`.
- {% extends %}
- A template tag that starts a child template by naming the base template it builds on. The child then fills the base's blocks.
- {% static %}
- A template tag, loaded with `{% load static %}`, that turns a static file's name into its URL, such as `/static/shop/style.css`.
- {% url %}
- A template tag that builds a link from a URL's name, so links keep working if you change a path in `urls.py`.
A
- admin site
- Django's ready-made pages, at `/admin/`, where staff can add, change and delete data once models are registered.
- ALLOWED_HOSTS
- A setting that lists the host names your site will answer to, such as `YOURNAME.pythonanywhere.com`. Django refuses requests for any other name, which shows as `Bad Request (400)`.
- app
- A folder of related models, views and templates that handles one part of a site, such as `shop` or `orders`. A project is made of apps.
- assertion
- A check inside a test that fails the test when it isn't true. `TestCase` provides methods such as `assertEqual`, `assertContains` and `assertRedirects`.
- attribute
- A named value stored on a Python object, read with a dot, such as `espresso.name`. Model fields are attributes of each object.
- attribute (HTML)
- Extra information inside an HTML opening tag, such as `lang="en"` or `href="/products/"`.
- authentication
- Finding out who someone is, usually with a username and password. Django's login system does this.
- authorization
- Deciding what a known user is allowed to do, such as letting only staff use the admin.
- auto-escaping
- Django's habit of swapping characters like `<` and `&` in template variables for safe codes. Product names or visitor text can't turn into HTML or running code.
- auto_now_add
- A `DateTimeField` option that fills in the current date and time when a row is first created, so nobody has to type it.
B
- blank=True
- A model field option that lets the field be left empty in forms and the admin. Without it the field is required.
- block
- A named gap in a base template that child templates can fill, such as `content` or `title` in Kettle & Crane's `base.html`.
- body
- The part of an HTTP request that carries data but isn't in the URL. POST forms send their fields there.
- browser
- The program, such as Chrome or Firefox, that asks servers for pages and shows them.
C
- check --deploy
- A command that checks your settings against Django's checklist for live sites and prints warnings such as W009 for a short `SECRET_KEY`.
- class
- A pattern for making objects. Each object made from it has its own values.
- class Meta
- A class written inside a model or form that Django reads for options rather than fields, such as `ordering`, `verbose_name_plural`, or which model and fields a `ModelForm` uses.
- class-based views, template partials, background tasks
- Three Django features: class-based views are ready-made classes for common list, detail and form pages; template partials are reusable pieces of a template; background tasks are jobs that run outside a web request.
- clean_<field> method
- A form method named `clean_` plus a field name that adds your own check for that field. It returns the value if fine, or raises `ValidationError`.
- cleaned_data
- A dict of a form's checked values, already turned into Python types. It is available after `is_valid()` returns `True`.
- collectstatic
- A command that copies every app's static files, including the admin's CSS, into one folder, `STATIC_ROOT`, so a real web server can serve them.
- column
- One fact stored about every row in a table, such as name or price. Each model field becomes a column.
- commit=False
- An option for `form.save()` that builds the object from the form without writing it to the database. You can set extra fields, such as the customer, then call `save()` yourself.
- context
- The dict of values a view passes to a template through `render()`. Each key becomes a variable in the template.
- cookie
- A short value the browser stores and sends back with every request to the same site. Django's login cookie holds only the session id.
- create() / save() / delete()
- Model methods for changing data: `create()` makes and saves a row in one go, `.save()` writes an object to the database, and `.delete()` removes its row.
- CSRF (cross-site request forgery)
- An attack where another website secretly submits a form to your site using a visitor's browser. Django blocks it by requiring a secret hidden field in every POST form.
- CSS (Cascading Style Sheets)
- A text format that says how HTML should look, written as rules with selectors and properties.
D
- database
- A program that stores data so it survives restarts and can be searched quickly. Data sits in tables made of rows and columns.
- date filter
- A template filter that formats a date using letter codes, such as `F` for the month name, `j` for the day and `Y` for the year.
- DEBUG
- A setting that makes Django show detailed yellow error pages while you build. It must be `False` on a live site, because those pages reveal your code and settings.
- decorator
- A line starting with `@` just above a function definition that wraps the function with extra behavior that runs first. `@login_required` is one.
- default (field option)
- A field option giving the value to use when none is supplied. A new field on a table that already has rows needs one, such as `default=True`.
- deploying
- Putting your site on a server on the internet so others can use it, as Kettle & Crane does with PythonAnywhere.
- development server
- The small server Django includes for trying your site on your own computer, started with `python manage.py runserver` (add a port, such as `runserver 8001`, to use another one).
- django-admin
- Django's command-line tool for tasks outside a project. Its `startproject` subcommand creates a new project with `manage.py` and a settings package.
- DoesNotExist
- The exception `.get()` raises when no row matches (`MultipleObjectsReturned` if more than one does). Use `.get()` only for unique values such as a slug.
- domain
- The part of a URL that names the computer, such as `shop.kettleandcrane.com`.
- dumpdata
- A command that prints an app's database rows in fixture format, so you can save or move them.
E
- element
- An HTML opening tag, its closing tag and everything between them, such as `<p>Fresh coffee</p>`.
- environment variable
- A named value set outside your program, in the terminal or by the server, which the program reads at startup. It keeps secrets such as the live `SECRET_KEY` out of your code.
F
- field
- A class attribute of a model that becomes one column of its table, such as `CharField` for short text or `DecimalField` for money.
- field lookup
- A condition in a filter made of a field name, two underscores and a test, such as `price__lte=16`. Double underscores can also follow a relationship, as in `category__slug`.
- filter (template)
- A change applied to a template value before printing, written after a `|`, such as `{{ product.name|upper }}` or `floatformat:2`.
- fixture
- A file of data, such as Kettle & Crane's `products.json`, that Django can load into the database with `loaddata`.
- force_login()
- A test-client method that signs a user in without the login form. `User.objects.create_user()` makes the test user, with a hashed password.
- ForeignKey
- A model field that links each row to one row of another model, such as each product to a category. It stores the other row's id.
- form
- In HTML, the part of a page where visitors type and submit data. Django's `Form` class writes the fields' HTML and checks the values.
- form.save()
- A `ModelForm` method that creates a database row from the form's cleaned data. With `commit=False` it only builds the object.
G
- GET
- The kind of request that fetches a page without changing anything. Search forms use it, putting their fields in the query string.
- get_object_or_404()
- A shortcut that does a `.get()` but raises `Http404` instead of `DoesNotExist` when nothing matches, so a missing product gives a Not Found page.
H
- hash
- A scrambled value made from a password that can be checked but not turned back. Django stores only the hash, never the password.
- HTML (HyperText Markup Language)
- The text format web pages are written in, using tags in angle brackets to mark what each part is.
- HTTP (HyperText Transfer Protocol)
- The set of rules browsers and servers use to exchange messages. Each visit is one request and one response.
- Http404
- An exception that Django turns into a Not Found (404) response.
- HttpResponse
- The Django class a view uses to build a response, with your text as the page and status code 200 by default.
- HTTPS
- The secure, encrypted version of HTTP, which protects data sent between a browser and a server. Django's `check --deploy` command warns about several settings that relate to it, such as `SECURE_SSL_REDIRECT` and `SECURE_HSTS_SECONDS`.
I
- include()
- A function that hands URL paths on to another URLconf, such as an app's `urls.py`.
- inheritance
- A class getting another class's methods and attributes, as `Product` does from `models.Model`.
- initial
- A form argument that gives fields starting values, such as pre-selecting a product in the order form.
- INSTALLED_APPS
- The settings list of apps and parts of Django the site uses. Django ignores any app not listed.
- is_authenticated
- An attribute on `user` that is true for logged-in visitors and false for anonymous ones. Templates use it to show different content.
- is_staff / is_superuser
- Two flags on `User`: `is_staff` lets someone log in to the admin, and `is_superuser` gives every permission.
- is_valid()
- A form method that checks every field and returns `True` or `False`. Afterwards `errors` or `cleaned_data` is available.
L
- list_display / list_filter / list_editable
- `ModelAdmin` options: `list_display` picks the list columns, `list_filter` adds a filtering side panel, `list_editable` lets you edit columns in the list, and `search_fields` and `prepopulated_fields` set the search box and auto-filled slugs.
- loaddata
- A command that loads a fixture file, such as `products.json`, into the database. Loading twice is safe because rows with the same `pk` are replaced.
- localhost
- The address `127.0.0.1`, which always means this computer. The development server is reached there.
- login()
- A Django function that starts a session for a user, so a newly signed-up customer is logged in at once. It isn't the login page.
- LOGIN_REDIRECT_URL / LOGOUT_REDIRECT_URL
- Settings that name the URL (by its name, such as `"home"`) where Django sends users after they log in or out.
M
- makemigrations
- A command that compares your models with existing migrations and writes a new migration file for the difference.
- manage.py
- The script in your project folder that runs Django commands for this project, such as `python manage.py runserver`.
- manager
- The object on each model, such as `Product.objects`, that starts database queries with methods like `all()`, `get()` and `create()`.
- messages
- A Django feature for one-time notes, such as "Order placed", that are stored during one request and shown on the next page the user sees.
- method
- A function defined inside a class. Its first parameter is `self`, the object it works on.
- migrate
- A command that runs migrations not yet applied, changing the database tables. Running it twice is safe.
- migration
- A Python file describing one change to the database tables, such as creating the product table. You create it with `makemigrations` and apply it with `migrate`.
- model
- A Python class, inheriting from `models.Model`, that describes one database table. Each object is a row and each field is a column.
- model field types
- The classes that say what kind of data a column holds, such as `CharField` (short text), `DecimalField` (exact money), `BooleanField` (yes/no) and `DateTimeField` (date and time).
- ModelAdmin
- A class that says how the admin site shows one model, with options such as `list_display`, `list_filter` and `search_fields`.
- ModelForm
- A form that builds its fields from a model, so `form.save()` can store the data as a row. `ContactForm` and `OrderForm` are examples.
N
- next parameter
- A query-string value on the login URL that remembers where the visitor was heading. After login, Django sends them there.
O
- object
- One thing made from a class, with its own values. A model object is one database row.
- on_delete
- A `ForeignKey` option that says what happens when the linked row is deleted. `PROTECT` refuses the deletion, while `CASCADE` deletes the related rows too.
- ordering
- A model `Meta` option that sets the default sort order of queries, such as `["name"]` for A to Z or `["-created"]` for newest first.
- ORM (object-relational mapper)
- The part of Django that lets you work with database rows as Python objects, writing the SQL for you.
- os.environ
- Python's dict-like view of environment variables, read through the `os` module. Kettle & Crane's settings use it for `SECRET_KEY` and `DEBUG`.
P
- package
- Code someone else wrote and published so anyone can install it. Django itself is a package.
- pagination
- Splitting a long list into pages so that only part of it is shown at a time. Django provides the `Paginator` class for this.
- password validators
- Django checks that refuse short or common passwords when someone signs up, with messages like "This password is too common."
- path
- The part of a URL after the domain, such as `/products/`, which names a page on the site.
- path converter
- A typed part of a URL pattern in angle brackets, such as `<slug:slug>` or `<int:id>`, that captures part of the path and passes it to the view.
- path()
- A function that connects a URL pattern to a view and gives the route a name. A list of them is called `urlpatterns`.
- pip
- The tool that installs Python packages from PyPI, such as `python -m pip install "django==6.1.*"`.
- pip freeze
- A command that lists the installed packages in the active virtual environment with their versions. Saving its output builds `requirements.txt`.
- port
- A numbered door on a computer that a server listens at, such as 8000 for the development server.
- POST
- The kind of request that sends data to change something, with the fields in the request body rather than the URL. POST forms need `{% csrf_token %}`.
- primary key
- A column that uniquely identifies each row. Django adds a numeric `id` primary key (1, 2, 3, …) to every model automatically, and fixtures call it `pk`.
- production
- The live copy of your site on a server on the internet, as opposed to the copy on your own computer.
- project
- The whole site: a folder of settings and code, created with `django-admin startproject`, that holds one or more apps.
- property (CSS)
- A named setting inside a CSS rule, such as `color` or `margin`, given a value.
- PyPI (Python Package Index)
- The website where Python packages are published, at pypi.org. pip downloads from it.
- PythonAnywhere
- A hosting service for Python websites that offers a free account with one web app at `YOURNAME.pythonanywhere.com`. It can be used to put a Django site such as Kettle & Crane online.
Q
- query string
- The part of a URL after `?`, made of `name=value` pairs joined by `&`, such as `?max=16`. Django exposes it as `request.GET`.
- QuerySet
- A list-like result of a database query. You can loop over it or keep narrowing it with `.filter()`, `.exclude()` and `.order_by()`.
R
- redirect
- A response with status 302 that tells the browser to load another URL with GET. Redirecting after a successful POST means refreshing doesn't resubmit the form.
- related_name
- A `ForeignKey` option naming the way back from the linked row, such as `category.products` for a category's products.
- relationship
- A link between two models, such as each product belonging to one category. The model linked to is the related model.
- render()
- A shortcut that fills a template with a context and returns the finished page as an `HttpResponse`.
- request
- What a browser sends to ask a server for a page. In Django it's the object passed to every view, holding the method, path, GET and POST data and user.
- request.GET / request.POST
- Parts of the request object: `request.GET` holds the query string, `request.POST` the submitted form data, `request.method` is `"GET"` or `"POST"`, and `request.user` is the visitor.
- requirements.txt
- A file listing a project's packages and versions, so a server can install the same ones with `pip install -r`.
- response
- What a server sends back to the browser: a status code and the page itself.
- REST API
- A way for programs to talk to a site over HTTP, usually by sending and receiving structured data such as JSON instead of web pages. In Django it is commonly built with Django REST Framework.
- reverse()
- The Python twin of `{% url %}`: it turns a URL name into its path, such as `/products/`. Tests use it.
- row
- One item in a database table, such as one product. In Django each row is one model object.
S
- SECRET_KEY
- A random string Django uses to sign cookies. Anyone who knows it could pretend to be a user, so the live key must not be kept in your code.
- selector
- The part of a CSS rule that picks which elements it applies to, such as `nav` or `.out-of-stock`.
- self
- The first parameter of a method, standing for the object it was called on. Python fills it in for you.
- server
- A program, running on another computer, that receives requests and sends back pages.
- session
- A small record Django keeps on the server saying who is logged in. The browser's cookie holds only its id.
- settings
- The Python file, `config/settings.py`, of capitalized options that control the whole site, such as `DEBUG` and `INSTALLED_APPS`.
- setUp
- A test method that runs before each test in a class to create the data the tests need, because the test database starts empty.
- shell
- A Python prompt with your project loaded, started with `python manage.py shell`, handy for trying queries on your models.
- showmigrations
- A command that lists migrations, marking applied ones with `[X]`.
- slug
- A short name of lowercase words joined by hyphens, safe to use in URLs, such as `house-espresso`.
- SQL (Structured Query Language)
- The language used to ask databases questions and change them. Django's ORM writes it for you.
- SQLite
- A database kept in one file, `db.sqlite3`, built into Python. New Django projects use it by default.
- sqlmigrate
- A command that prints the SQL a migration would run, without running it.
- staff
- An account allowed to log in to the admin site. A superuser is always staff.
- startapp
- A command that creates a new app folder, such as `shop`. You then add it to `INSTALLED_APPS`.
- static file
- A file that's the same for every visitor, such as CSS, images or JavaScript, as opposed to a page built for each request.
- STATIC_ROOT
- The setting naming the folder where `collectstatic` gathers all static files, so a real web server can serve them.
- status code
- A number in a response that says how the request went: 200 OK, 302 redirect (look elsewhere), 404 Not Found, 500 the server's program crashed.
- superuser
- An account allowed to do everything in the admin, created with `python manage.py createsuperuser`. Jo's account is one.
T
- table
- A database's spreadsheet-like storage for one kind of thing, such as products. Each row is one item and each column is one fact.
- tag (HTML)
- A marker in angle brackets, such as `<p>`, that says what a part of an HTML page is. Most come in opening and closing pairs.
- tag (template)
- A `{% %}` command in a template that does something, such as a loop, a test or a URL lookup. Each needs its closing tag.
- template
- An HTML file with gaps that Django's template engine fills with data. Templates live in `app/templates/app/`.
- template inheritance
- Sharing one layout across pages: a base template defines blocks and child templates use `{% extends %}` to fill them.
- test
- Code that uses your site and checks the results, so one command can confirm everything still works after a change.
- test client
- A fake browser available as `self.client` in tests. It sends requests to your site without a server and returns the responses.
- test database
- An empty temporary database Django builds from your migrations when running tests and deletes afterwards, so real data is safe.
- TestCase
- The class that tests inherit from. Each method whose name starts with `test_` is one test.
U
- unique=True
- A model field option meaning no two rows may share that value, such as a product slug.
- URL (Uniform Resource Locator)
- A page's web address, made of a domain and a path, such as `https://shop.kettleandcrane.com/products/`.
- URL name
- The `name=` given to a `path()`, which lets `{% url %}`, `reverse()` and `redirect()` refer to a URL without typing its path.
- URLconf
- The list of URL patterns, in `urls.py`, that says which view answers which path.
- User
- Django's built-in model for accounts, with `username`, `email`, hashed `password`, `date_joined` and more. It comes from the `django.contrib.auth` app.
- UserCreationForm
- A ready-made `ModelForm` for creating a `User`, with a username and two password boxes, used for the sign-up page.
V
- ValidationError
- An exception a form's check raises to mark a field invalid and show your message next to it.
- variable (template)
- A value in double braces in a template, such as `{{ product.name }}`, replaced when the page is built. The dot reads dict keys, attributes and methods.
- venv
- A folder holding its own copy of Python's package list for one project, so different projects can use different Django versions. You activate it in each terminal.
- verbose_name_plural
- A model `Meta` option that sets the plural name the admin shows, such as "categories" instead of "Categorys".
- view
- A Python function that takes a request and returns a response, such as `product_list`.
W
- web framework
- A library that does the common work of a website's server program, so you write only what's special to your site. Django is one.
- widget
- The HTML control a form field is drawn with, such as `forms.Textarea` for a large many-line box.
- WSGI (Web Server Gateway Interface)
- The standard way a web server runs a Python web app. Django's `config/wsgi.py` and PythonAnywhere's WSGI file use it.