def _get_api_response(self, data): json_data = json.dumps(data) factory = APIRequestFactory() view = CategoryView.as_view({'post': 'create'}) request = factory.post('/categories/', json_data, content_type='application/json') return view(request)
from django.urls import path from categories.views import CategoryView, CategoryPostView app_name = 'categories' urlpatterns = [ path('', CategoryPostView.as_view(), name='category_post'), path('<int:pk>', CategoryView.as_view(), name='category_get') ]
urlpatterns = [ path('admin/', admin.site.urls), path('signin', LoginView.as_view(), name='rest_login'), path('signup', RegisterView.as_view(), name='rest_register'), path( 'user/<int:pk>', UserView.as_view({ 'get': 'retrieve', 'put': 'update', 'delete': 'destroy' })), path('task/create', TaskView.as_view({'post': 'create'})), path( 'task/<int:pk>', TaskView.as_view({ 'get': 'retrieve', 'put': 'update', 'delete': 'destroy' })), path('task>', TaskView.as_view({'get': 'list'})), path( 'category/<int:pk>', CategoryView.as_view({ 'get': 'retrieve', 'put': 'update', 'delete': 'destroy' })), path('category', CategoryView.as_view({'get': 'list'})), path('category/create', CategoryView.as_view({'post': 'create'})) ]
from django.contrib import admin from django.urls import path from categories.views import CategoriesView, CategoryView urlpatterns = [ path('admin/', admin.site.urls), path('categories/', CategoriesView.as_view()), path('categories/<int:id>/', CategoryView.as_view()) ]
from django.conf.urls import patterns, include, url from django.views.generic.base import TemplateView from categories.views import CategoryDataView, CategoryView urlpatterns = patterns( '', url(r'^$', TemplateView.as_view(template_name='categories/categories.html'), name='categories_page'), url( r'^(?P<pk>\d+)/$', CategoryView.as_view(), name='category_detail', ), url( r'^get_data/$', CategoryDataView.as_view(), name='categories_all', ), )
"""categoriesAPI URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/3.0/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: path('', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin from django.urls import path from categories.views import CategoryView urlpatterns = [ path('admin/', admin.site.urls), path('categories/<int:pk>/', CategoryView.as_view()), path('categories/', CategoryView.as_view()), ]