I am making a Django-based API and here is my urls.py.
from django.conf.urls import include, url
api_version = "v1"
urlpatterns = [
url(r'^v1/', include( "api."+ api_version +".urls", namespace=api_version )),
]
What I want to do is to retrieve API version from http accept header. I tried to use django.http.HttpRequest module, which didn't do the trick.
Is there any way to achieve this?
You can't access request on
urls.py
, see: How Django processes a requestYou can configure versioning on django-rest-framework and get
version
on request object like:Or use
URLPathVersioning
approach.