jjzjj

attributeerror

全部标签

python - Django AttributeError 模型对象没有属性 'filter'

我正在尝试使用Django创建自己的博客。我有一个View来显示一篇从DetailView扩展而来的文章。为避免slug带来任何麻烦,我尝试根据文章的发布日期对文章进行分类。文章的url是这样的(其中pk对应于文章的slug):r'articles/(?P\d{4})/(?P\d{2})/(?P\d{2})/(?P[\w-]+)/$'在我看来我想这样做:defget_queryset(self):year=self.kwargs.get("year",None)month=self.kwargs.get("month",None)day=self.kwargs.get("day",No

python - Heroku ---> 安装 pip 远程 : AttributeError: module 'pip._vendor.requests' has no attribute 'Session'

一个Python3.6Django==11应用程序正在部署,并且代码会定期推送到昨天。现在我有错误:remote:AttributeError:module'pip._vendor.requests'hasnoattribute'Session'整个轨迹:Countingobjects:3,done.Deltacompressionusingupto4threads.Compressingobjects:100%(2/2),done.Writingobjects:100%(3/3),273bytes|0bytes/s,done.Total3(delta1),reused0(delta0

python - 如何更正错误 ' AttributeError: ' dict_keys' object has no attribute 'remove' '?

我正在尝试使用dijkstra算法进行最短路径查找,但它似乎不起作用。无法弄清楚问题是什么。这是代码和错误消息。(我正在使用Python3.5。https://www.youtube.com/watch?v=LHCVNtxb4ss)graph={'A':{'B':10,'D':4,'F':10},'B':{'E':5,'J':10,'I':17},'C':{'A':4,'D':10,'E':16},'D':{'F':12,'G':21},'E':{'G':4},'F':{'E':3},'G':{'J':3},'H':{'G':3,'J':3},'I':{},'J':{'I':8},}d

python - 属性错误 : Class Instance has no __call__ method

我对python有点陌生,但熟悉OOP。我正在尝试使用PyGame编写游戏。基本上,我的目标是每隔几秒渲染一次树,并在屏幕上移动树矩形。这是我的代码:fromcollectionsimportdequeimportpygame,random,syspygame.init()size=800,600screen=pygame.display.set_mode(size)classtree:def__init__(self):self.img=pygame.image.load("tree.png")self.rect=self.img.get_rect()defrender(self):

python - Django 帮助 : AttributeError: 'module' object has no attribute 'Charfield'

我看过几个类似的其他属性的帖子,但没有找到。Python和Django的新手-我已经完成了几个教程的第一部分,包括Django的“投票”教程,当它到达我为我的应用程序同步数据库的地步时,我总是得到'AttributeError:'module'对象没有属性CharField.在模型中,我完全按照教程所说的进行复制:从django.db导入模型classPoll(models.Model):question=models.Charfield(max_length=200)pub_date=models.DateTimeField('datepublished')classChoice(m

python - 在使用 @property 装饰器时在属性的 setter 方法中使用 super() 会引发 AttributeError

尝试覆盖子类中的属性时,我对这种行为感到有些困惑。第一个示例设置了两个类,Parent和Child。Parent继承自object,而Child继承自Parent。属性a是使用属性装饰器定义的。当调用child.a的setter方法时,会引发AttributeError。在第二个示例中,通过使用property()函数而不是装饰器,一切都按预期工作。谁能阐明为什么行为不同?另外,是的,我知道不需要Child中的__init__定义。示例1-使用@propertyclassParent(object):def__init__(self):self._a='a'@propertydefa(

python - 用于 Python 的 OpenCV - AttributeError : 'module' object has no attribute 'connectedComponents'

我正在使用以下OpenCV教程尝试分水岭算法:https://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_imgproc/py_watershed/py_watershed.html#watershed我已经修复了一个错误,现在代码如下所示:importnumpyasnpimportcv2frommatplotlibimportpyplotaspltfromsysimportargvimg=cv2.imread(argv[1])gray=cv2.cvtColor(img,cv2.COLOR_BGR2G

python - 使用 os.scandir() 引发 AttributeError : __exit__

当我使用来自python文档(here)的示例代码时,引发了AttributeError。示例代码如下:withos.scandir(path)asit:forentryinit:ifnotentry.name.startswith('.')andentry.is_file():print(entry.name)结果是一个AttributeError:D:\Programming>test.pyTraceback(mostrecentcalllast):File"D:\Programming\test.py",line3,inwithos.scandir()asit:Attribute

python - AttributeError : module object has no attribute "Series". 代码在 iPython 中有效

子模块不是隐式导入的,必须显式声明,但我正在显式调用pd.Series子模块,不是吗?无论如何,importpandasaspd难道不应该允许调用pd.Series吗?以下代码在iPython中完美运行,但在从脚本执行时失败。#!/usr/bin/env/python2.7#-*-coding:utf-8-*-importpandasaspdimportnumpyasnpcounts=pd.Series([632,1638,569,115],index=["Firmicutes","Proteobacteria","Actinobacteria","Bacteroidetes"])结果

python - Flask 登录 AttributeError : 'User' object has no attribute 'is_active'

我有一个关于flask-login的问题。填写登录表单并单击“提交”后,出现此错误:Flask-loginAttributeError:'User'对象没有属性'is_active'创建了一些测试用户。登录模板没有问题回溯:Traceback(mostrecentcalllast):File"C:\flask_prj\project\venv\lib\site-packages\flask\app.py",line1836,in__call__returnself.wsgi_app(environ,start_response)File"C:\flask_prj\project\ven