Django错误缺少位置参数(请求)

时间:2018-02-16 21:17:59

标签: python django

我正在尝试使用Django构建一个webapp并使用基于Djano类的视图来调用views.py中的其他函数。我对编程很新,并且认为我在这里让自己感到困惑。

我收到了以下错误:

  

make_connection_to_user()缺少1个必需的位置参数:   '请求'

Views.py:

from .models import UserInfo

def make_connection_to_user(request):
    current_user = UserInfo.objects.get(user_id=request.user.id)
    user_token = current_user.access_token
    connection = MyApp(user_token)
    return connection

def get_user_info():
    used = make_connection_to_user().users_get_space_usage().used
    allocated_space = make_connection_to_user().users_get_space_usage().allocation.get_individual().allocated
    return used, allocated

class DashboardMainPage(View):

    def get(self, request):
        used_space = get_user_space_info()[0]
        allocated_space = get_user_space_info()[1]
        return render(request, 'analyzer/dashboard.html',
                      {'used_space': used_space, 'allocated_space': allocated_space})

Urls.py:

urlpatterns = [
    path('dashboard/', views.DashboardMainPage.as_view(), name='dashoard'),
]

1 个答案:

答案 0 :(得分:0)

used = make_connection_to_user().users_get_space_usage().used

这调用make_connection_to_user()没有参数,但是你将它定义为需要一个参数:

def make_connection_to_user(request):
   ...