__init __()得到了一个意外的关键字参数'lookup_type'

时间:2017-11-13 18:37:54

标签: django python-3.x django-rest-framework

请帮助我为什么这个错误会在远程服务器上发生,但它在本地计算机上工作正常,请找到以下错误示例。

Request Method:     GET
Request URL:    https:***********.***?job_function=dir&job_type=parttime&max_experience=100&min_experience=3&name=test&owner_id=571&page_size=10
Django Version:     1.8.14
Exception Type:     TypeError
Exception Value:    

__init__() got an unexpected keyword argument 'lookup_type'

Exception Location:     env/local/lib/python3.4/dist-packages/django/forms/fields.py in __init__, line 245
Python Executable:  env/bin/python3.4
Python Version:     3.4.3
Python Path:    

 '/home/deployment/backend',
 '/home/deployment/backend/env/bin',
 '/home/deployment/backend',
 '',
 '/home/deployment/backend/env/local/lib64/python3.4/site-packages',
 '/home/deployment/backend/env/local/lib/python3.4/site-packages',
 '/home/deployment/backend/env/lib64/python3.4',
 '/home/deployment/backend/env/lib/python3.4',
 '/home/deployment/backend/env/lib64/python3.4/site-packages',
 '/home/deployment/backend/env/lib/python3.4/site-packages',
 '/home/deployment/backend/env/lib64/python3.4/plat-linux',
 '/home/deployment/backend/env/lib64/python3.4/lib-dynload',
 '/home/deployment/backend/env/local/lib/python3.4/dist-packages',
 '/usr/lib64/python3.4',
 '/usr/lib/python3.4'
  

代码:

请在这里找到给定的代码,它可以在本地机器上工作但是远程服务器出错,这里有两个在Jobviewsets类中定义的函数

def get_annotate_queryset(self,queryset):

#queryset = queryset.filter(Q(job_for='all') | Q(job_for=''))
queryset = queryset.annotate(
    all_applicant_count=Count('applicants', distinct=True),
    job_view_count=Count('job_views', distinct=True),
).extra(select={
    'voteup_count': get_voteup_count_query(queryset.model),
    'has_applied':
        """
        SELECT Sum(CASE WHEN {job_applicant}.user_id = {user_id} THEN 1 ELSE 0 END)
        FROM {job_applicant}
        WHERE job_id={job}.id
        """.format(user_id=self.request.user.id,
            job=Job._meta.db_table,
            job_applicant=Applicant._meta.db_table),
    'is_favourite':
        """
        SELECT Sum(CASE WHEN {favourite_job}.user_id = {user_id} THEN 1 ELSE 0 END)
        FROM {favourite_job}
        WHERE job_id={job}.id
        """.format(user_id=self.request.user.id,
            job=Job._meta.db_table,
            favourite_job=FavouriteJob._meta.db_table)
})
return queryset

def get_queryset(self):

queryset = super().get_queryset()
queryset = self.get_annotate_queryset(queryset)
if self.action == 'discover':

    searchtype=self.request.GET.get('search_type')
    searchKeyword=self.request.GET.get('name')
    searchLocation=self.request.GET.get('location')

    job_status=self.request.GET.get('job_status')
    if(job_status =='' or job_status== None):
        job_status = 'active'

    job_type=self.request.GET.get('job_type')
    if (job_type =='' or job_type == None):
        job_type = 'fulltime'

    min_experience=self.request.GET.get('min_experience')
    if (min_experience =='' or min_experience == None):
        min_experience = 0

    max_experience=self.request.GET.get('max_experience')
    if (max_experience =='' or max_experience == None):
        max_experience = 100

    min_salary_compensation=self.request.GET.get('min_salary_compensation')
    if (min_salary_compensation == None):
        min_salary_compensation = 0

    max_salary_compensation=self.request.GET.get('max_salary_compensation')
    if (max_salary_compensation =='' or max_salary_compensation == None):
        max_salary_compensation = 500000

    salary_reccurence=self.request.GET.get('salary_reccurence')
    if (salary_reccurence =='' or salary_reccurence == None):
        salary_reccurence = 'hourly'

    if (searchtype == 'refine_search'):

        if (searchKeyword == '' or searchKeyword == None):
            searchKeyword = ''

        if (searchLocation == '' or searchLocation == None):
            searchLocation = ''

        min_experience = int(min_experience)
        max_experience = int(max_experience)
        min_salary_compensation = int(min_salary_compensation)
        max_salary_compensation = int(max_salary_compensation)

        queryset = queryset.filter(Q(job_title__icontains=searchKeyword) |
                                   Q(company_name__icontains=searchKeyword) |
                                   Q(location_id=searchLocation) |
                                   Q(status=job_status) |
                                   Q(employment_type__icontains=job_type) |
                                   Q(min_experience__gte=min_experience) &
                                   Q(max_experience__lte=max_experience) |

                                   Q(compensation__gte=min_salary_compensation) &
                                   Q(compensation__lte=max_salary_compensation) |
                                   Q(salary_reccurence__icontains=salary_reccurence)

                                   ).exclude(owner=self.request.user)

    if (searchtype != 'refine_search'):

        if (searchKeyword != None and searchLocation != None):

            queryset = queryset.filter(Q(job_title__icontains=searchKeyword) |
                                       Q(company_name__icontains=searchKeyword) |
                                       Q(location_id=searchLocation)).exclude(owner=self.request.user)

        elif (searchKeyword != None and searchLocation == None):
            queryset = queryset.filter(Q(job_title__icontains=searchKeyword) |
                                       Q(company_name__icontains=searchKeyword)).exclude(
                owner=self.request.user)

        elif (searchKeyword == None and searchLocation != None):
            queryset = queryset.filter(Q(location_id=searchLocation)).exclude(owner=self.request.user)

        else:
            queryset = queryset.exclude(owner=self.request.user)

return queryset

1 个答案:

答案 0 :(得分:0)

我们需要查看正在实例化的类的构造函数方法,以确切地找出出错的地方。

然而,仅从错误消息中看来,有一个额外的参数被传递给无法识别的构造函数。看看课程中定义的形式参数'构造函数并将其与传入的参数进行比较。