简体   繁体   English

'模块'对象不可调用typeError Django

[英]'module' object is not callable typeerror django

So I have a module that I successfully use. 因此,我有一个成功使用的模块。 But now I added another file to module and it gives me this error. 但是现在我向模块添加了另一个文件,它给了我这个错误。

I have a file generate_bags_uk that has method: 我有一个具有方法的文件generate_bags_uk

def generate_bags(bags, price):

And I use it like this: 我这样使用它:

from excelgenerator import generate_bags_uk
...
uk_bag = generate_bags_uk.generate_bags(tshirts, form.cleaned_data['price_uk_bag'])

And I get TypeError: module is not callable. 我得到TypeError:模块不可调用。 What am I doing wrong here ? 我在这里做错了什么?

Try the following code instead - 请尝试以下代码-

from excelgenerator.generate_bags_uk import generate_bags
...
uk_bag = generate_bags(tshirts, form.cleaned_data['price_uk_bag'])

and make sure excelgenerator folder has a __init__.py inside it, otherwise it will not be dealt as a python package. 并确保excelgenerator文件夹中包含__init__.py ,否则它将不会作为python包处理。

Also, I guess the method has a body, if it does not then at least give it a definition - 另外,我猜该方法有一个主体,如果没有,则至少给它一个定义-

def generate_bags(bags, price):
    pass

COMMENT : From the looks of this error, the error is happening in file /home/marijus/workspace/tshirtnation/excelgenerator/generate_bags_uk.py . 评论 :从此错误的外观来看,该错误发生在文件/home/marijus/workspace/tshirtnation/excelgenerator/generate_bags_uk.py I think your other calls are also of similar format and thus causing error. 我认为您的其他通话格式也相似,因此会导致错误。 Please change them as I mentioned. 如我所说,请更改它们。 The problem should be solved. 该问题应解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM