【发布时间】:2019-09-26 18:19:33
【问题描述】:
我想在另一个文件 plots.py 中使用下面的 x 作为函数 get_price() 中的变量。
views.py
class ScatterView(TemplateView) :
def get(self, request, *args, **kwargs) :
context = super().get_context_data(**kwargs)
context['form'] = SampleForm()
x = request.GET.get('x')
context['calculated_x'] = plots.get_price()
return render(request, 'index.html', context)
plot.py
def get_price():
input_x = x + 1
return input_x
但它不起作用。 我该如何描述这个目的的功能? 关键是,我需要稍后通过views.py使用模板的返回值。
【问题讨论】:
-
您需要将
x变量传递给get_price(x)函数并对其进行处理。
标签: python django function view arguments