from django.conf.urls import url, include
from django.views.generic import RedirectView

from .api import LinkedEventsAPIRouter

from django.contrib import admin
admin.autodiscover()

api_router = LinkedEventsAPIRouter()



urlpatterns = [
    url(r'^(?P<version>(v0.1|v1))/', include(api_router.urls)),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^accounts/', include('allauth.urls')),
    url(r'^$', RedirectView.as_view(url='/v1/', permanent=False)),
]

from django.core.urlresolvers import reverse
from django.conf.urls import url, include
from django.views.generic import RedirectView

from .api import LinkedEventsAPIRouter

from django.contrib import admin
admin.autodiscover()

api_router = LinkedEventsAPIRouter()


class RedirectToAPIRootView(RedirectView):
    permanent = False

    def get_redirect_url(self, *args, **kwargs):
        return reverse('api-root', kwargs={'version': 'v1'})

urlpatterns = [
    url(r'^(?P<version>(v0.1|v1))/', include(api_router.urls)),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^accounts/', include('allauth.urls')),
    url(r'^$', RedirectToAPIRootView.as_view()),
]

Make redirect-to-API work even with URL prefix
Make redirect-to-API work even with URL prefix

+ from django.core.urlresolvers import reverse
  from django.conf.urls import url, include
  from django.views.generic import RedirectView
  
  from .api import LinkedEventsAPIRouter
  
  from django.contrib import admin
  admin.autodiscover()
  
  api_router = LinkedEventsAPIRouter()
  
  
+ class RedirectToAPIRootView(RedirectView):
+     permanent = False
+ 
+     def get_redirect_url(self, *args, **kwargs):
+         return reverse('api-root', kwargs={'version': 'v1'})
  
  urlpatterns = [
      url(r'^(?P<version>(v0.1|v1))/', include(api_router.urls)),
      url(r'^admin/', include(admin.site.urls)),
      url(r'^accounts/', include('allauth.urls')),
-     url(r'^$', RedirectView.as_view(url='/v1/', permanent=False)),
+     url(r'^$', RedirectToAPIRootView.as_view()),
  ]
  
Make redirect-to-API work even with URL prefix
## Code Before:
from django.conf.urls import url, include
from django.views.generic import RedirectView

from .api import LinkedEventsAPIRouter

from django.contrib import admin
admin.autodiscover()

api_router = LinkedEventsAPIRouter()



urlpatterns = [
    url(r'^(?P<version>(v0.1|v1))/', include(api_router.urls)),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^accounts/', include('allauth.urls')),
    url(r'^$', RedirectView.as_view(url='/v1/', permanent=False)),
]

## Instruction:
Make redirect-to-API work even with URL prefix
## Code After:
from django.core.urlresolvers import reverse
from django.conf.urls import url, include
from django.views.generic import RedirectView

from .api import LinkedEventsAPIRouter

from django.contrib import admin
admin.autodiscover()

api_router = LinkedEventsAPIRouter()


class RedirectToAPIRootView(RedirectView):
    permanent = False

    def get_redirect_url(self, *args, **kwargs):
        return reverse('api-root', kwargs={'version': 'v1'})

urlpatterns = [
    url(r'^(?P<version>(v0.1|v1))/', include(api_router.urls)),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^accounts/', include('allauth.urls')),
    url(r'^$', RedirectToAPIRootView.as_view()),
]
