如果模板名称==“ 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个
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})