Django如何从同一文件夹下的另一个文件导入文件?

时间:2018-10-26 14:56:39

标签: python django

这是我的Django项目结构:

const data = [{
    id: 1,
    condition: 1,
    helpers: [{id: 1, condition: null}, {id: 2, condition: 2}]
  },{
    id: 2,
    condition: null,
    helpers: [{id: 1, condition: 1}, {id: 2, condition: null}]
}];

const conds = [{
    id: 1,
    conditions: {
       rules: ['test', 'foo']
    }
  },{
    id: 2,
    conditions: {
       rules: ['#hashtag', 'foo']
    }
}];

data.forEach(function(item) {
  item.condition = conds.find(x => x.id === item.id).conditions.rules;
});

console.log(data);

在myfile.py里面,我想在task.py里面导入test()函数:

project/
    app1/
        static/
        templates/
        utils/
        __init__.py
        admin.py
        forms.py
        tasks.py
        urls.py
        views.py
        myfile.py

控制台错误:

from . import tasks
tasks.test()

那怎么解决呢?

1 个答案:

答案 0 :(得分:1)

尝试使用-

from .tasks import test

from app1 import tasks
tasks.test()