Reputation: 168
i'm trying to create a custom get_context_data, but i'm getting the error get_context_data() takes 1 positional argument but 2 were given, and I don't know why
can someone help me?, why i'm getting this error?, and how i can solve it?
thanks in advance
class JobDetail(DetailView):
model = Job
template_name = 'employer/job_detail.html'
def get_context_data(self, **kwargs):
context = super(JobDetail, self).get_context_data(kwargs)
job = Job.objects.all()
sign_job = False
if self.request.user.is_authenticated():
get_job = SignJob.objects.filter(user=self.request.user, job=job) # TODO:look at how to get the job the right way
if self.request.method == 'POST':
SignJob.objects.create(user=self.request.user, job=job)
sign_job = get_job.exists()
context['sign_job'] = sign_job
return context
Upvotes: 2
Views: 506
Reputation: 1514
You forget to depack the kwargs
arguments:
context = super(JobDetail, self).get_context_data(kwargs)
Should be:
context = super(JobDetail, self).get_context_data(**kwargs)
Also, just a small suggestion, you can rewrite your get_context_data
method like this:
def get_context_data(self, **kwargs):
job = Job.objects.all()
sign_job = False
if self.request.user.is_authenticated():
get_job = SignJob.objects.filter(user=self.request.user, job=job) # TODO:look at how to get the job the right way
if self.request.method == 'POST':
SignJob.objects.create(user=self.request.user, job=job)
sign_job = get_job.exists()
return super(JobDetail, self).get_context_data(
sign_job=sign_job,
**kwargs
)
Upvotes: 1