QamoosTech
Web & APIsRouting and viewsIntermediateDjangoPython

Path Converter

PronunciationPATH kun-VER-ter

Definition

A path converter is the part of a URL pattern that captures a piece of the path and converts it to a type, such as <int:id> giving your view a real integer.

Where you hear it

In Django URL patterns, FastAPI path parameters, and route docs such as /circles/<int:id>/.

Examples

  • Use <int:id> so a non-number gives a 404 before the view runs.
  • The slug converter allows letters, numbers and hyphens.
  • The URL /orders/<int:id>/ rejects abc before the view runs.

Common mistake

Using a plain string and converting in the view. The converter validates earlier and keeps views clean.

Don't confuse with

A query parameter (?page=2), which comes after the path and is optional. A path converter is part of the path itself.

Say it at work

  • In a meeting or chatWhich converter handles the id here?
  • In an email or ticketAdd a custom converter for the date format.