Django如何将请求函数中的值导入到函数中?

费德里科·德马可

我有以下项目结构:

_stato_patrimoniale
___views.py

_iva
___utility.py

在 stato patrimonale 我有以下代码:

from iva.utility import my_func 

def stato_patrimoniale(request):
    now=datetime.datetime.now()
    last_account_year=float(now.year)-1 #definizione dell'ultimo anno contabile
    now = now.year
    if request.method == 'POST':
        year = request.POST['year']
        if year != '':
            now = year
            last_account_year = float(now) - 1

    data=my_func()
    iva_a_credito=data['iva_a_credito']

现在在我的iva.utility我有以下代码:

def my_func():
  pass

现在我想导入from 的my_func()这怎么可能?last_account_yearstato_patrimoniale

文森特

将值作为参数传递

视图.py:

from iva.utility import my_func

def stato_patrimoniale(request):
    now=datetime.datetime.now()
    last_account_year=float(now.year)-1 #definizione dell'ultimo anno contabile
    now = now.year
    if request.method == 'POST':
        year = request.POST['year']
        if year != '':
            now = year
            last_account_year = float(now) - 1

    data=my_func(last_account_year)
    iva_a_credito=data['iva_a_credito']

其他文件:

def my_func(last_account_year)
    // do something with last_account_year

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

将 Redux 中的 Props 直接导入到函数中

如何将数据框中的特定值导入到 Pandas 中的变量中

如何将Cocoapod导入到App Extension中?

如何将AvroKeyValueOutputFormat文件导入到蜂巢中?

如何将swift类导入到ViewController中?

如何将firefox cookie导入到python请求

如何使用ES6将JavaScript函数导入到Polymer 1.0组件中?

如何将.txt文件中的“高级格式”滑块问题导入到Qualtrics中?

如何将各个模块中的选择对象导入到 __init__.py 中?

如何将excel表中的数据同时导入到关系表中

PHP无法将全局变量导入到类内部的函数中

将模块内的所有函数和类导入到python类中

如何将外部数据获取api导入到react componentDidMount方法中

如何将矩阵导入到Matlab脚本代码中

如何将子组件正确导入到延迟加载的IonicPage中?

如何将这种excel格式导入到这种数据库格式中?

如何将扫描仪导入到名为System的类中

如何将csv文件导入到mysql表中并自动递增

如何将数据从 JSON 文件导入到嵌入中?

如何将现有资源导入到单独子目录中的 terraform?

如何将Google表格的行导入到Pandas中,但要带有列名?

如何将道具导入到组件中正在渲染的功能中

如何将静态信息(包括图像)动态导入到ViewController中

如何将导入到python中的数据从csv文件转换为时间序列?

如何将Firebase导入到app模块以外的模块中?

如何将googleapis npm包导入到meteor中

我如何将 Azure 构建管道数据导入到 Elasticsearch 的本地安装中

如何将这种格式化的txt文件导入到SQL Server表中

如何将json文件内容作为文档导入到mongodb中?