Versioning APIs

A snippet showing how to add API versioning in DRF.


# settings.py

REST_FRAMEWORK = {
    "DEFAULT_VERSIONING_CLASS": "rest_framework.versioning.NamespaceVersioning",
    "DEFAULT_VERSION": "v1",
    "ALLOWED_VERSIONS": ["v1", "v2"],
}
      

# urls.py

from django.urls import include, path
from .views import ArticleList

urlpatterns = [
    path("api/v1/articles/", ArticleList.as_view(), name="article-list",),
    path("api/v2/articles/", ArticleList.as_view(), name="article-list"),
]
      
Explanation:
  • Versioned endpoints let you evolve APIs without breaking clients.
Previous snippet
SearchFilter Example
Never miss a story on Django.wiki

Subscribe for fresh tutorials, snippets, and updates.

By subscribing you agree to our Privacy Policy.