def get_urls(self): """ Generate the list of URL patterns, including a default root view for the API, and appending `.json` style format suffixes. """ urls = [] if self.include_root_view: root_url = url(r'^REST$', self.get_api_root_view(), name=self.root_view_name) urls.append(root_url) default_urls = super(DefaultRouter, self).get_urls() urls.extend(default_urls) if self.include_format_suffixes: urls = format_suffix_patterns(urls) return urls
def get_urls(self): """ Generate the list of URL patterns, including a default root view for the API, and appending `.json` style format suffixes. """ # don't change to use current class else the json suffixes get appended twice urls = super(DefaultRouter, self).get_urls() if self.include_root_view: if self.schema_title: view = self.get_schema_root_view(api_urls=urls) else: view = self.get_api_root_view(api_urls=urls) # this is the only thing changed! root_url = url(self.root_url, view, name=self.root_view_name) urls.append(root_url) if self.include_format_suffixes: urls = format_suffix_patterns(urls) return urls
from django.urls import path from rest_framework.routers import format_suffix_patterns from .views import * urlpatterns = [ path('users/register/', UserCreateAPIView.as_view(), name="register"), path('users/auth/', obtain_auth_token, name='auth'), path('all-users/', get_all_user_api_view, name="all-users"), path('profile/', get_update_profile_api_view, name="profile") ] urlpatterns = format_suffix_patterns(urlpatterns)
annotations_list = views.AnnotationViewSet.as_view({ "get": "list", "post": "create", }) annotations_detail = views.AnnotationViewSet.as_view({ "get": "retrieve", "put": "update", "patch": "partial_update", "delete": "destroy", }) annotations_search = views.AnnotationViewSet.as_view({ "get": "search", }) annotations_root = views.AnnotationViewSet.as_view({ "get": "root", }) urlpatterns = format_suffix_patterns([ url(r"^demo/?$", views.DemoView.as_view(), name="demo"), url(r"^$", annotations_root, name="root"), url(r"annotations/?$", annotations_list, name="annotations-list"), url(r"annotations/(?P<pk>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/?$", annotations_detail, name="annotations-detail"), url(r"search/?$", annotations_search, name="annotations-search"), ])
from . import views urlpatterns = format_suffix_patterns([ # Answers urls path('polls/<int:pk>/answers/', views.AnswerViewSet.as_view({ 'post': 'create', 'get': 'list' })), # Polls CRUD path( 'polls/<int:pk>/', views.PollViewSet.as_view({ 'get': 'retrieve', 'put': 'update', 'delete': 'destroy' })), path('polls/', views.PollViewSet.as_view({ 'get': 'list', 'post': 'create' })), # Question CRUD path('questions/<int:pk>/', views.QuestionViewSet.as_view({ 'put': 'update', 'delete': 'destroy' })), path('questions/', views.QuestionViewSet.as_view({'post': 'create'})), ])