Django - missing 1 required positional argument: 'request'
我遇到了错误
get_indiceComercioVarejista() missing 1 required positional argument:
'request'
尝试访问方法get_indiceComercioVarejista时。 我不知道这是怎么回事。
意见:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | from django.http import JsonResponse from django.shortcuts import render, HttpResponse import requests import pandas as pd from rest_framework.views import APIView from rest_framework.response import Response class ChartData(APIView): authentication_classes = [] permission_classes = [] def get(self, request, format=None): data = { 'customer' : 10, 'sales': 100 } return Response(data) def get_indiceComercioVarejista(self, request, format=None): data = { 'customer' : 10, 'sales': 100 } return Response(data) |
网址:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | from django.conf.urls import url from . import views from django.contrib.auth.views import login urlpatterns = [ url(r'^$', views.home), url(r'^login/$', login, {'template_name': 'Oraculum_Data/login.html'}), url(r'^cancerColo/$', views.cancerColo), url(r'^educacao/$', views.educacao), url(r'^comercio/$', views.comercio), url(r'^saude/$', views.saude), url(r'^api/chart/data/$', views.ChartData.as_view()), url(r'^api/chart/indiceVolumeReceitaComercioVarejista/$', views.ChartData.get_indiceComercioVarejista) ] |
有谁可以帮助我吗?
这就是为什么从
1 2 3 4 5 6 | def get_indiceComercioVarejista(request, format=None): data = { 'customer' : 10, 'sales': 100 } return Response(data) |
我认为最好的方法是将
例如:
view.py
1 2 3 4 5 6 | def get_indiceComercioVarejista(request, format=None): data = { 'customer' : 10, 'sales': 100 } return Response(data) |
urls.py
1 | url(r'^api/chart/indiceVolumeReceitaComercioVarejista/$', views.get_indiceComercioVarejista) |
另一种解决方案是使用ViewSet,在使用DRF时建议使用ViewSet。