gpt4 book ai didi

python - Django - 缺少 1 个必需的位置参数 : 'request'

转载 作者:太空宇宙 更新时间:2023-11-03 11:42:47 24 4
gpt4 key购买 nike

我遇到了错误

get_indiceComercioVarejista() missing 1 required positional argument: 'request'

尝试访问方法 get_indiceComercioVarejista 时。我不知道它有什么问题。

观看次数:

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

这就是为什么从 ChartData 类中提取 get_indiceComercioVarejista 是个好主意:

def get_indiceComercioVarejista(request, format=None):
data = {
'customer' : 10,
'sales': 100
}
return Response(data)

关于python - Django - 缺少 1 个必需的位置参数 : 'request' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45720065/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com