我收到了这个错误,我不知道为什么会发生。 在/admin/ofac_sdn/ofac_sdn处的类型错误/ +的操作数类型不受支持:“int”和“strTypeError”。
我上传了一个csv直接到我的模型。 这些是我在csv中使用的字段。在
36,AEROCARIBBEAN AIRLINES,null ,CUBA,null,null,null,0,0,null,null,null
173,"ANGLO-CARIBBEAN CO., LTD.",null,CUBA,null,null,null,0,0,null,null,null
306,BANCO NACIONAL DE CUBA,null,CUBA,null,null,null,0,0,null,null,a.k.a. 'BNC'.
我的管理员是这样的:
^{pr2}$以下是我的模型:
class Ofac_Sdn(models.Model):
number = models.IntegerField(blank=True, null=True)
name = models.CharField(max_length=200, null=True)
b_i = models.CharField(max_length=250, null=True)
programe= models.CharField(max_length=250, null=True)
more_info = models.CharField(max_length=250, null=True)
vessel_call_sign = models.CharField(max_length=250, null=True)
vessel_type= models.CharField(max_length=250, null=True)
vessel_dwt = models.IntegerField(blank=True, null=True)
tonnage = models.IntegerField(blank=True, null=True)
vessel_flag = models.CharField(max_length=250, null=True)
vessel_owner= models.CharField(max_length=250, null=True)
dob_aka= models.CharField(max_length=250, null=True)
以下是我的网址:
urlpatterns = [
url(r'^ofac/', include('ofac_sdn.urls')),
url(r'^admin/', admin.site.urls),
这就是我的观点。没有创建视图,但我应该看到在这个ofac_sdn表/模型中的输入。在
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse("<h1> Hi Cohen</h1>")
问题是我可以从应用程序中看到我的数据库中的记录,但它们不会显示在管理员中。提前谢谢你!在
以下是完整的错误:
TypeError at /admin/ofac_sdn/ofac_sdn/
unsupported operand type(s) for +: 'int' and 'str'
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/ofac_sdn/ofac_sdn/
Django Version: 1.11.4
Exception Type: TypeError
Exception Value:
unsupported operand type(s) for +: 'int' and 'str'
Exception Location: /Users/cohen/my-python-project/venv/ofac/ofac_project/ofac_sdn/models.py in __str__, line 34
Python Executable: /Users/cohen/my-python-project/venv/bin/python
Python Version: 3.6.1
Python Path:
['/Users/cohen/my-python-project/venv/ofac/ofac_project',
'/Users/cohen/anaconda/lib/python36.zip',
'/Users/cohen/anaconda/lib/python3.6',
'/Users/cohen/anaconda/lib/python3.6/lib-dynload',
'/Users/cohen/my-python-project/venv/lib/python3.6/site-packages']
Server time: Tue, 5 Sep 2017 08:42:29 +0000
Error during template rendering
In template /Users/cohen/my-python-project/venv/lib/python3.6/site-packages/django/contrib/admin/templates/admin/base.html, error at line 75
unsupported operand type(s) for +: 'int' and 'str'
65 <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message|capfirst }}</li>
66 {% endfor %}</ul>
67 {% endif %}
68 {% endblock messages %}
69
70 <!-- Content -->
71 <div id="content" class="{% block coltype %}colM{% endblock %}">
72 {% block pretitle %}{% endblock %}
73 {% block content_title %}{% if title %}<h1>{{ title }}</h1>{% endif %}{% endblock %}
74 {% block content %}
75 {% block object-tools %}{% endblock %}
76 {{ content }}
77 {% endblock %}
78 {% block sidebar %}{% endblock %}
79 <br class="clear" />
80 </div>
81 <!-- END Content -->
82
83 {% block footer %}<div id="footer"></div>{% endblock %}
84 </div>
85 <!-- END Container -->
Traceback Switch to copy-and-paste view
/Users/cohen/my-python-project/venv/lib/python3.6/site-packages/django/db/models/options.py in get_field
return self.fields_map[field_name] ...
▼ Local vars
Variable Value
field_name
'__str__'
self
<Options for Ofac_Sdn>
您正在某处添加一个字符串和一个int,可能是这样的一行代码:
您应该使用适当的格式替换这个
^{pr2}$+
,例如或者
如果您确实需要使用
+
,则必须先将int
转换为str
:谢谢你们!你是对的!问题是我的意见。它有一个
'+'
并且以某种方式纠正了错误。我可以把+
符号改成逗号,现在它可以正常工作了。在相关问题 更多 >
编程相关推荐