Home > Enterprise >  Why do I get this error "HttpRequest.accepts() missing 1 required positional argument: 'me
Why do I get this error "HttpRequest.accepts() missing 1 required positional argument: 'me

Time:09-20

The source code originally had Httpsrequest.is_ajax which after some reading I realised was depricated. So I changed it to Httpsrequest.accepts and it now throws an error:

HttpRequest.accepts() missing 1 required positional argument: 'media_type'

How can I solve or bypass this error ?

def home_view(request):

    published_jobs = Job.objects.filter(is_published=True).order_by('-timestamp')
    jobs = published_jobs.filter(is_closed=False)
    total_candidates = User.objects.filter(role='employee').count()
    total_companies = User.objects.filter(role='employer').count()
    paginator = Paginator(jobs, 3)
    page_number = request.GET.get('page', None)
    page_obj = paginator.get_page(page_number)

    if request.accepts():
        job_lists = []
        job_objects_list = page_obj.object_list.values()
        for job_list in job_objects_list:
            job_lists.append(job_list)

    return render(request, 'jobapp/index.html', context)

CodePudding user response:

if request.accepts(): #Returns True if the request Accept header matches the mime_type argument.

Ex: request.accepts('text/html') #Add your mime_type argument here to solve this error.

I hope this helps you

  • Related