如何解决__init __()需要1个位置参数,但给出了2个位置

时间:2019-08-06 22:29:03

标签: sql django django-templates

我有一个搜索表,可以将存储的记录返回给用户。 我想要的是能够返回模板名称并基于模板名称。

  • 如果模板名称==“ create_folder_test.html”,查询将 在文件夹类上过滤
  • 如果模板名称==“ blog / list.html”,查询将过滤为 班级嫌疑犯

    发生的情况是,一旦用户提交搜索表单,它就会显示以下错误:

  在/ folder / search /处的

TypeError    init ()接受1个位置参数,但给出了2个位置参数请求方法:GET请求URL:http://127.0.0.1:8000/folder/search/?q=121   Django版本:2.1.3异常类型:TypeError异常值:
   init ()接受1个位置参数,但给定2个例外位置:C:\ Users \ LT   GM \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages \ django \ core \ handlers \ base.py   在_get_response中,第124行Python可执行文件:C:\ Users \ LT   GM \ AppData \ Local \ Programs \ Python \ Python37 \ python.exe Python   版本:3.7.1

     

环境:

     

请求方法:GET请求URL:   http://127.0.0.1:8000/folder/search/?q=121

     

Django版本:2.1.3 Python版本:3.7.1已安装的应用程序:   ['django.contrib.admin','django.contrib.auth',   'django.contrib.contenttypes','django.contrib.sessions',   'django.contrib.messages','django.contrib.staticfiles','blog',   'widget_tweaks','import_export']已安装的中间件:   ['django.middleware.security.SecurityMiddleware',   'django.contrib.sessions.middleware.SessionMiddleware',   'django.middleware.common.CommonMiddleware',   'django.middleware.csrf.CsrfViewMiddleware',   'django.contrib.auth.middleware.AuthenticationMiddleware',   'django.contrib.messages.middleware.MessageMiddleware',   'django.middleware.clickjacking.XFrameOptionsMiddleware']

     

跟踪:

     

文件“ C:\ Users \ LT   GM \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages \ django \ core \ handlers \ exception.py“   在内部     34. response = get_response(request)

     

文件“ C:\ Users \ LT   GM \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages \ django \ core \ handlers \ base.py“   在_get_response中     126. response = self.process_exception_by_middleware(e,request)

     

文件“ C:\ Users \ LT   GM \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages \ django \ core \ handlers \ base.py“   在_get_response中     124. response = wrapd_callback(request,* callback_args,** callback_kwargs)

     

异常类型:/ folder / search /处的TypeError异常值:    init ()接受1个位置参数,但给出了2个

views.py

class searchFolder(TemplateView):
    template_name = "create_folder_test.html"

    def get_template_names(self):
        template_name = self.template_name
        return [template_name]

    def search(request):
        query = request.GET.get('q')
        return get_template_names()
        # try:
        print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>", len(query))
        print("search for :",query)
        FilterQuery = Folder.objects.filter(Q(FolderNum__icontains = query))
        print("FilterQuery============================", FilterQuery)
        ListID = list(FilterQuery)
        if query == "":
            messages.error(request,"Search field is empty!")
            print("Search field is empty!!!!!!!!!!!!!!!!")
            return redirect('create_folder_test')
        elif ListID == []:
            messages.error(request,"Record not found/does not exist!")
            print("Record does not exist!!!!!!!!!!!!!!!!")
            return redirect('create_folder_test')
        else:
            return render(request, 'blog/update2.html', {'FilterRecords': ListID})

0 个答案:

没有答案