我在尝试访问get_indiceComercioVarejista方法时遇到了错误:
缺少1个必需的位置参数:'request'
我不知道出了什么问题。
视图:
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)
网址:
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)
]
有人可以帮助我吗,请?
.get
来实现这个功能,并在你的urls中使用views.ChartData.as_view()
...(或者如果你有多个get方法,可以在apiview的prepare/dispatch方法中选择合适的get方法,根据任何标准...) - Jon Clements