我想将值从邮政表格传递到get_context_data
函数。但是问题是,当我在post
函数中使用该值时,它会打印正确的值,例如:self.start_date
,但我在get_context_data
中打印的却是None
。当我删除此行start_date = None
时,它给出了错误'JobListView' object has no attribute 'start_date'
。
class JobListView(LoginRequiredMixin, generic.TemplateView):
template_name = 'admin/jobs/job.html'
# if i remove this then i get error 'JobListView' object has no attribute 'start_date'
start_date = None
def get_context_data(self, **kwargs):
context = super(JobListView, self).get_context_data(**kwargs)
company_name = self.request.user.userprofile.user_company
context['jobs'] = Jobs.objects.exclude(job_is_deleted = True)
context['form'] = JobSearchForm()
print(self.start_date) # this print as None
return context
def post(self, request, *args, **kwargs):
self.start_date = self.request.POST.get('start_date',None)
print(self.start_date) # this print correct value from form
return HttpResponseRedirect('/useradmin/job/')