Python 在django中使用count函数获取数据

Python 在django中使用count函数获取数据,python,database,django,error-handling,Python,Database,Django,Error Handling,我试图使用django中的count函数从数据库中提取数据,每当我使用tablename.objects.count()尝试这段代码时,都会发现它工作得很好。我试试这个:- views.py:- def home(request): getsessionuserid = request.session['getuser_id'] getlatestproject = jobs.objects.all() getcountvalues = applicationform.o

我试图使用django中的count函数从数据库中提取数据,每当我使用tablename.objects.count()尝试这段代码时,都会发现它工作得很好。我试试这个:-

views.py:-

def home(request):
    getsessionuserid = request.session['getuser_id']
    getlatestproject = jobs.objects.all()
    getcountvalues = applicationform.objects.count(user_id=getsessionuserid)    
    getinterviewcount = interview.objects.count()   
    getjobscount = jobs.objects.count()
    return render_to_response(
    'home.html',
    { 'user': request.user, 'getlatestproject': getlatestproject , 'getcountvalues': getcountvalues, 'getinterviewcount': getinterviewcount , 'getjobscount': getjobscount }
    ) 
然后显示一个错误:-

count()获得意外的关键字参数“user\u id”

我想在user_id=getSessionSerid但显示错误的情况下对数据进行计数。

count()方法不接受任何参数。您可以先过滤查询集,然后使用count。例如:

published_count = Book.objects.filter(published=True).count()

我强烈建议您使用该系统,而不是自己跟踪会话中的用户ID。我强烈建议您在变量名中使用一些下划线,以便于阅读。