我想在其他文件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下面使用其他文件plot.py中的get_price()函数中的变量。 views.py类ScatterView(TemplateView):def get(自己,请求,* args,** kwargs):context = ...
为什么不只是通过?将您的代码更改为如下所示:
一旦有了变量x
。您需要在函数中传递它。