Python 获取上下文数据方法不';我不在django工作
我有一个从CreateView继承的基于类的视图,我有一些字段希望通过上下文字典发送到页面中,而get_context_数据不起作用,因为页面中没有出现上下文字段的任何部分 班级:Python 获取上下文数据方法不';我不在django工作,python,django,web,Python,Django,Web,我有一个从CreateView继承的基于类的视图,我有一些字段希望通过上下文字典发送到页面中,而get_context_数据不起作用,因为页面中没有出现上下文字段的任何部分 班级: class IncomeCreateListView(CreateView): template_name = 'users/incomes_&_spendings.html' form_class = IncomeCreateForm def get_context_date(se
class IncomeCreateListView(CreateView):
template_name = 'users/incomes_&_spendings.html'
form_class = IncomeCreateForm
def get_context_date(self, **kwargs):
context = super().get_context_data(self, **kwargs)
incomes = Incomes.objects.filter(
user=self.request.user, created_date__year=datetime.now().year, created_date__month=datetime.now().month)
if datetime.now().month == 1:
incomes_last_month = Incomes.objects.filter(
user=self.request.user, created_date__year=datetime.now().year - 1, created_date__month=datetime.now().month + 11)
else:
incomes_last_month = Incomes.objects.filter(
user=self.request.user, created_date__year=datetime.now().year, created_date__month=datetime.now().month - 1)
total_incomes = round(assembly(incomes), 2)
total_incomes_last_month = round(
assembly(incomes_last_month), 2)
context['title'] = 'Incomes'
context['object_name'] = 'Incomes'
context['primary_color'] = 'primary'
context['objects'] = incomes
context['total_sum'] = total_incomes
context['total_sum_last_month'] = total_incomes_last_month
context['year'] = datetime.now().year,
context['month'] = datetime.now().month,
return context
def form_valid(self, form):
return super().form_valid(form)
你写了
get\u context\u datE
,而它的get\u context\u datA
天哪,thanx:Dnp,有一个很好的答案,如果不难的话,请接受答案:)对不起,我去旅行了,当时我没有,现在我接受了