gpt4 book ai didi

Django get() 缺少 1 个必需的位置参数 : 'header'

转载 作者:行者123 更新时间:2023-12-03 23:35:19 26 4
gpt4 key购买 nike

每次我成功发布请求时,我都会收到此消息。我知道这与实现重定向功能有关,因此您不会收到双重帖子,但我无法使其正常工作。这是我的代码。谢谢您的帮助。

@login_required
def K8_Points_Test(request):
if request.method == 'POST':
form = K8PointsTestForm(request.POST)
if form.is_valid():
form.save(commit=False)
class_name = form.cleaned_data.get('class_name')
getstudents = Student.objects.filter(class_name = class_name)
students = getstudents.all()
context = {'form': form ,'students' : students , 'class_name': class_name}
return render(request, 'points/k8_points_test.html', {'form': form} )
else:
return HttpResponseBadRequest
else:
form = K8PointsTestForm()
return render(request, 'points/k8_points_test.html', {'form': form} )


追溯
Environment:


Request Method: POST
Request URL: http://127.0.0.1:8000/points/k8_points_test

Django Version: 2.2.6
Python Version: 3.7.3
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'forms.apps.FormsConfig',
'crispy_forms',
'users.apps.UsersConfig',
'points.apps.PointsConfig']
Installed Middleware:
['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']



Traceback:

File "C:\Users\rzuchowski\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\handlers\exception.py" in inner
34. response = get_response(request)

File "C:\Users\rzuchowski\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\deprecation.py" in __call__
96. response = self.process_response(request, response)

File "C:\Users\rzuchowski\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\middleware\clickjacking.py" in process_response
26. if response.get('X-Frame-Options') is not None:

Exception Type: TypeError at /points/k8_points_test
Exception Value: get() missing 1 required positional argument: 'header'

最佳答案

这一行:

return HttpResponseBadRequest  

导致错误。您需要返回响应类的实例,而您正在返回类本身。

这应该解决它:
return HttpResponseBadRequest()

# OR you can also pass a custom message
return HttpResponseBadRequest("Bad Request")

关于Django get() 缺少 1 个必需的位置参数 : 'header' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59201954/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com