Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django get() missing 1 required positional argument: 'header'

Every time i do a successful post request i get this message. I know it has something to do with implementing the redirect function so you don't get a double post, but i cant get it to work right. Here is my code. Thanks for the help.

@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} )  

Traceback

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'
like image 512
Ray Zuchowski Avatar asked Dec 13 '22 09:12

Ray Zuchowski


1 Answers

This line:

return HttpResponseBadRequest  

is causing the error. You need to return an instance of the response class, whereas you're returning the class itself.

This should fix it:

return HttpResponseBadRequest()

# OR you can also pass a custom message
return HttpResponseBadRequest("Bad Request")
like image 152
xyres Avatar answered Feb 05 '23 22:02

xyres