本文介绍了Django-缺少1个必需的位置参数:"request"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到错误
当尝试访问方法get_indiceComercioVarejista时.我不知道这是怎么回事.
when trying to access the method get_indiceComercioVarejista. I don't know what it's wrong with it.
观看次数:
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)
]
请问有人可以帮我吗?
推荐答案
request
作为第一个参数传递.您的第一个参数是 self
.
request
is passed as a first argument. Your first argument is self
.
这就是为什么从 ChartData
类中提取 get_indiceComercioVarejista
是一个好主意的原因:
This is why it would be a good idea to extract get_indiceComercioVarejista
from ChartData
class:
def get_indiceComercioVarejista(request, format=None):
data = {
'customer' : 10,
'sales': 100
}
return Response(data)
这篇关于Django-缺少1个必需的位置参数:"request"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!