GVKun编程网logo

TypeError:只能将元组(不是'nt')连接到元组

1

在本文中,我们将详细介绍TypeError:只能将元组的各个方面,并为您提供关于不是'nt'连接到元组的相关解答,同时,我们也将为您带来关于BraintreeDjango异常“只能将str(而不是“元

在本文中,我们将详细介绍TypeError:只能将元组的各个方面,并为您提供关于不是'nt'连接到元组的相关解答,同时,我们也将为您带来关于Braintree Django 异常“只能将 str(而不是“元组”)连接到 str"、Discord.js - TypeError:client.on 不是函数、Django URLs TypeError:对于include(),视图必须是可调用的或列表/元组、is_authenticated()引发TypeError TypeError:'bool'对象不可调用的有用知识。

本文目录一览:

TypeError:只能将元组(不是'nt')连接到元组

TypeError:只能将元组(不是'nt')连接到元组

我正在尝试从db返回值并收到此错误。我在这里尝试了先前回答的问题,但是没有运气。有人可以帮助我吗?

@frappe.whitelist()def generate_barcode():    last_barcode = frappe.db.sql("""\        select MAX(barcode) from `tabItem` """)    if last_barcode:        last_barcode = last_barcode + 1    else:        x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]        random.shuffle(x)        last_barcode = x[0]    return {''last_barcode'':last_barcode}

添加回溯:

Traceback (innermost last):File "/home/adminuser/frappe-bench-hitech/apps/frappe/frappe/app.py", line 49, in   applicationresponse = frappe.handler.handle()File "/home/adminuser/frappe-bench-hitech/apps/frappe/frappe/handler.py", line 66, in handleexecute_cmd(cmd)File "/home/adminuser/frappe-bench-hitech/apps/frappe/frappe/handler.py", line 89, in execute_cmdret = frappe.call(method, **frappe.form_dict)File "/home/adminuser/frappe-bench-hitech/apps/frappe/frappe/__init__.py", line 531, in   callreturn fn(*args, **newargs)File "/home/adminuser/frappe-bench-hitech/apps/erpnext/erpnext/stock/doctype/item/item.py", line 405, in generate_barcodelast_barcode = last_barcode + 1TypeError: can only concatenate tuple (not "int") to tuple

答案1

小编典典

我以某种方式得到了答案。感谢大家的帮助。

@frappe.whitelist()def generate_barcode():last_barcode_auto = frappe.db.sql("""\    select MAX(barcode) from `tabItem` """)if last_barcode_auto[0][0] :    last_barcode = last_barcode_auto[0][0]    final_barcode= last_barcode+1else:    final_barcode=random.randrange(100001, 100000000000, 2)return {''final_barcode'':final_barcode}

Braintree Django 异常“只能将 str(而不是“元组”)连接到 str

Braintree Django 异常“只能将 str(而不是“元组”)连接到 str"

谢谢你这么详细的问题!

错误就是线索。它说你试图连接一个元组和一个不允许的字符串。由于该行是 return "/merchants/" + self.merchant_id 并且我没有看到表示无关元组的逗号,这意味着问题出在 self.merchant_id 上。这似乎是从 settings.BT_MERCHANT_ID 设置的。我的预感是 settings.BT_MERCHANT_ID 在它的末尾有一个逗号,它不应该导致它成为一个元组。

例如:

x = 1

导致 x 被设置为整数 1。但是

x = 1,

导致 x 被设置为元组 (1,)。这是一个痛苦的陷阱,最终会咬住每个 Python 开发人员。

Discord.js - TypeError:client.on 不是函数

Discord.js - TypeError:client.on 不是函数

您没有正确创建 client。您需要在 event code 的最顶部添加:

const Discord = require('discord.js');
const client = new Discord.Client();
,

您没有正确声明“客户端”,请确保添加此 -

const { Client }= require('discord');
const client = new Client()

Django URLs TypeError:对于include(),视图必须是可调用的或列表/元组

Django URLs TypeError:对于include(),视图必须是可调用的或列表/元组

升级到Django 1.10后,出现错误:

TypeError: view must be a callable or a list/tuple in the case of include().

我的urls.py如下:

from django.conf.urls import include,url

urlpatterns = [
    url(r'^$','myapp.views.home'),url(r'^contact/$','myapp.views.contact'),url(r'^login/$','django.contrib.auth.views.login'),]

完整的回溯是:

Traceback (most recent call last):
  File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/utils/autoreload.py",line 226,in wrapper
    fn(*args,**kwargs)
  File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/core/management/commands/runserver.py",line 121,in inner_run
    self.check(display_num_errors=True)
  File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/core/management/base.py",line 385,in check
    include_deployment_checks=include_deployment_checks,File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/core/management/base.py",line 372,in _run_checks
    return checks.run_checks(**kwargs)
  File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/core/checks/registry.py",line 81,in run_checks
    new_errors = check(app_configs=app_configs)
  File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/core/checks/urls.py",line 14,in check_url_config
    return check_resolver(resolver)
  File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/core/checks/urls.py",line 24,in check_resolver
    for pattern in resolver.url_patterns:
  File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/utils/functional.py",line 35,in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/urls/resolvers.py",line 310,in url_patterns
    patterns = getattr(self.urlconf_module,"urlpatterns",self.urlconf_module)
  File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/utils/functional.py",line 303,in urlconf_module
    return import_module(self.urlconf_name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py",line 37,in import_module
    __import__(name)
  File "/Users/alasdair/dev/urlproject/urlproject/urls.py",line 28,in <module>
    url(r'^$',File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/conf/urls/__init__.py",line 85,in url
    raise TypeError('view must be a callable or a list/tuple in the case of include().')
TypeError: view must be a callable or a list/tuple in the case of include().

is_authenticated()引发TypeError TypeError:'bool'对象不可调用

is_authenticated()引发TypeError TypeError:'bool'对象不可调用

如何解决is_authenticated()引发TypeError TypeError:''bool''对象不可调用?

当您尝试表现对象的方法或功能时,会发生“对象不可调用”错误。

在这种情况下:

current_user.is_authenticated()

您将current_user.is_authenticated表现为一种方法,而不是一种方法。

您必须以这种方式使用它:

current_user.is_authenticated

您在方法或函数(而不是对象)之后使用“()”。

在某些情况下,类可能实现了__call__也可以调用对象的函数,因此它将是可调用的。

解决方法

我尝试is_authenticated()在视图中使用,但收到错误`TypeError:’bool’对象不可调用。为什么会出现此错误,我该如何解决?

@auth.before_app_request
def before_request():
    if current_user.is_authenticated() \
            and not current_user.confirmed \
            and request.endpoint[:5] != ''auth.'' \
            and request.endpoint != ''static'':
        return redirect(url_for(''auth.unconfirmed''))

关于TypeError:只能将元组不是'nt'连接到元组的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于Braintree Django 异常“只能将 str(而不是“元组”)连接到 str"、Discord.js - TypeError:client.on 不是函数、Django URLs TypeError:对于include(),视图必须是可调用的或列表/元组、is_authenticated()引发TypeError TypeError:'bool'对象不可调用的相关信息,请在本站寻找。

本文标签: