URL Converters#

Shared opaque-key URL path converters (edx-platform ADR 0038, rule 9), so conforming API routes resolve course and usage keys once, hand views parsed keys, and turn malformed or deprecated keys into consistent 404s.

class CourseKeyConverter#

Match non-deprecated course run keys (course-v1:, ccx-v1:).

Views receive a parsed CourseKey; reverse() accepts a CourseKey (or its string form).

to_python(value: str) → CourseKey#

Parse value; raise ValueError (→ 404) if invalid or deprecated.

to_url(value: CourseKey) → str#

Serialize for reverse().

class UsageKeyConverter#

Match non-deprecated usage keys (block-v1:, lb:, …).

Views receive a parsed UsageKey; reverse() accepts a UsageKey (or its string form).

to_python(value: str) → UsageKey#

Parse value; raise ValueError (→ 404) if invalid or deprecated.

to_url(value: UsageKey) → str#

Serialize for reverse().

register_url_converters()#

Register the shared converters under the names course_key and usage_key. Call once per service, from the project URLconf, before any URL pattern that uses <course_key:...> or <usage_key:...>.