草庐IT

Object-C

全部标签

python - 属性错误 : 'RegexURLPattern' object has no attribute '_callback'

我是python新手。我用了这个教程http://www.django-rest-framework.org/tutorial/quickstart/,但RegexURLPattern有问题。问题的完整堆栈跟踪:Unhandledexceptioninthreadstartedby.wrapperat0x103c8cf28>Traceback(mostrecentcalllast):File"/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/Django-1.10.dev20151

python - TypeError at/'str' object is not a mapping in django template

我正在尝试在标签内设置链接,当我按照代码中的步骤执行此过程时,出现错误:TypeErrorat/'str'objectisnotamapping它曾经工作得很好,但后来决定不工作了模板代码:网址代码:urlpatterns=[path('admin/',include('admin_llda.urls')),path('about/',views.about,name='about'),path('dashboard/',views.dashboard,name='dashboard'),path('',views.homepage,name='home')]

python - 属性错误 : type object 'datetime.date' has no attribute 'now'

使用这些代码行:fromdatetimeimportdatedate_start=date.now()我收到这个错误:AttributeError:typeobject'datetime.date'hasnoattribute'now'我该如何解决这个问题? 最佳答案 你需要使用importdatetimenow=datetime.datetime.now()或者如果您使用的是django1.4+并且启用了时区,您应该使用django.utils.timezone.now() 关于pyt

多处理中的 Python 日志记录 : AttributeError: 'Logger' object has no attribute 'flush'

基于此code我创建了一个python对象,它既将输出打印到终端,又将输出保存到一个日志文件,并在其名称后附加日期和时间:importsysimporttimeclassLogger(object):"""Createsaclassthatwillbothprintandloganyoutputtext.Seehttps://stackoverflow.com/a/5916874fororiginalsourcecode.Modifiedtoadddateandtimetoendoffilename."""def__init__(self,filename="Default"):sel

python - 属性错误 : 'Namespace' object has no attribute 'check'

我正在尝试在命令行上使用不同的参数运行python脚本。有一个位置参数(num),其他是可选参数。我尝试运行[pythonnewping.py10-c]但出现以下错误。有什么我无法弄清楚的错误吗?importargparsedeffibo(num):a,b=0,1foriinrange(num):a,b=b,a+b;returna;defMain():parser=argparse.ArgumentParser(description="Tothefindthefibonaccinumberofthegivenumber")arg1=parser.add_argument("num",

python 2.7 : replace method of string object deprecated

我的“同事”刚刚告诉我,字符串对象的replace方法已被弃用,将在3.xx中删除。请问是不是真的,为什么,如果是,怎么替换(举例)?非常感谢。 最佳答案 documentation3.2中没有提到应该删除str类型的replace方法。我也看不出为什么有人应该这样做。删除的是string中的replace函数模块。一个例子:"bla".replace("a","b")调用str类型的replace方法。string.replace("bla","a","b")调用字符串模块的替换函数。也许这就是您的同事所混淆的。使用字符串模块函数

python - ORA-01861 : literal does not match format string when executing get model object in django

我在django中有一个模型对象,就像这样......fromdjango.dbimportmodelsclassPerson(models.Model):employee_title=models.CharField(max_length=150)pk_person_id=models.IntegerField(primary_key=True)department_name=models.CharField(max_length=240)cost_center=models.CharField(max_length=150)user_name=models.CharField(ma

Python 的 AttributeError : 'module' object has no attribute 'require_version'

我正在使用Python3.4。我正在尝试打开一个应用程序,该应用程序据称使用Python但似乎无法使其正常工作。我确实收到以下错误:Traceback(mostrecentcalllast):File"pychess",line24,ingi.require_version("Gtk","3.0")AttributeError:'module'objecthasnoattribute'require_version' 最佳答案 按照JoãoCartucho的建议,使用pipinstallPyGTK安装依赖项。

python - celery + Django 错误 : TypeError: 'Settings' object is not subscriptable

我遇到了这个问题,但我完全不知道它是从哪里来的。我使用的代码与theCelerytutorial中提供的代码完全相同除了我将项目目录也用作我唯一的应用程序目录这一事实(因此,拥有models.py、views.py并将“proj”添加到INSTALLED_APPS)。奇怪的是,在我的本地机器上尝试这个设置时,错误总是出现在每个django命令(迁移、shell...)中。删除virtualenv并重新安装misteriously修复了它。现在,将应用程序推送到Heroku时,我遇到了同样的问题,无法正常工作。有什么提示吗?谢谢!ps:Python3.4.2,Django1.8.4,Ce

python - 类型错误 : 'int' object has no attribute '__getitem__' error because of possible erratum in book

我正在阅读新书“DataSciencefromScratch:FirstPrincipleswithPython”,我想我发现了一个勘误表。当我运行代码时,我得到"TypeError:'int'objecthasnoattribute'__getitem__'".我认为这是因为当我尝试选择friend["friends"],friend是一个我不能子集化的整数。那是对的吗?我怎样才能继续练习以获得想要的输出?它应该是friend的friend列表(foaf)。我知道存在重复问题,但这些问题稍后会修复...users=[{"id":0,"name":"Ashley"},{"id":1,"