[英]import issue with python/django
I'm trying to use the calendar
module in my Django views.py file. 我正在尝试在我的Django views.py文件中使用
calendar
模块。 If I make the import at the top of the file, with the rest of my package imports, and call the monthrange
function on the module, I get the following: 如果我在文件的顶部进行导入,使用我的包导入的其余部分,并在模块上调用
monthrange
函数,我会得到以下内容:
'function' has no attribute 'monthrange'
'function'没有属性'monthrange'
If however I import the module in my function, where I make use of monthrange
it works fine. 但是,如果我在我的函数中导入模块,在那里我使用
monthrange
它工作正常。
This has left me scratching my head. 这让我摸不着头脑。 Any ideas?
有任何想法吗?
Seems like namespace clash - maybe 'calendar' got redefined some place as a variable or function name. 看起来像命名空间冲突 - 也许“日历”被重新定义为某个地方作为变量或函数名称。
Try to import monthrange from calendar at the top of the module, 'monthrange' is much less likely to clash with a variable or function elsewhere the code. 尝试从模块顶部的日历导入月份范围,'monthrange'不太可能与代码中的变量或函数冲突。
from calendar import monthrange
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.