from django.conf.urls import patterns, url, include
from api import views

# The API URLs are now determined automatically by the router.
# Additionally, we include the login URLs for the browseable API.
urlpatterns = patterns('',
    # list of all readings
    url(r'^api/all', views.ApiRoot.as_view()),

    # list of all readings from a single sensor
    url(r'^api/readings/$', views.Read.as_view()),

    # put method to update data
    url(r'^api/record/$', views.record),

    url(r'^api/create/$', views.CreateRecord.as_view()),
)

from django.conf.urls import url, include
from api.views import ReadingViewSet, UserViewSet
from rest_framework.routers import DefaultRouter

router = DefaultRouter()
router.register(r'readings', ReadingViewSet)
router.register(r'users', UserViewSet)

urlpatterns = [
    url(r'^', include(router.urls)),
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]
Use routers instead of manual routes
Use routers instead of manual routes

- from django.conf.urls import patterns, url, include
+ from django.conf.urls import url, include
- from api import views
+ from api.views import ReadingViewSet, UserViewSet
+ from rest_framework.routers import DefaultRouter
  
+ router = DefaultRouter()
+ router.register(r'readings', ReadingViewSet)
+ router.register(r'users', UserViewSet)
- # The API URLs are now determined automatically by the router.
- # Additionally, we include the login URLs for the browseable API.
- urlpatterns = patterns('',
-     # list of all readings
-     url(r'^api/all', views.ApiRoot.as_view()),
  
+ urlpatterns = [
+     url(r'^', include(router.urls)),
+     url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
+ ]
-     # list of all readings from a single sensor
-     url(r'^api/readings/$', views.Read.as_view()),
- 
-     # put method to update data
-     url(r'^api/record/$', views.record),
- 
-     url(r'^api/create/$', views.CreateRecord.as_view()),
- )
- 
Use routers instead of manual routes
## Code Before:
from django.conf.urls import patterns, url, include
from api import views

# The API URLs are now determined automatically by the router.
# Additionally, we include the login URLs for the browseable API.
urlpatterns = patterns('',
    # list of all readings
    url(r'^api/all', views.ApiRoot.as_view()),

    # list of all readings from a single sensor
    url(r'^api/readings/$', views.Read.as_view()),

    # put method to update data
    url(r'^api/record/$', views.record),

    url(r'^api/create/$', views.CreateRecord.as_view()),
)

## Instruction:
Use routers instead of manual routes
## Code After:
from django.conf.urls import url, include
from api.views import ReadingViewSet, UserViewSet
from rest_framework.routers import DefaultRouter

router = DefaultRouter()
router.register(r'readings', ReadingViewSet)
router.register(r'users', UserViewSet)

urlpatterns = [
    url(r'^', include(router.urls)),
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]