回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我收到了这个错误,我不知道为什么会发生。
<em>在/admin/ofac_sdn/ofac_sdn处的类型错误/
+的操作数类型不受支持:“int”和“strTypeError”。</em></p>
<p>我上传了一个csv直接到我的模型。
这些是我在csv中使用的字段。在</p>
<pre><code>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'.
</code></pre>
<p>我的管理员是这样的:</p>
^{pr2}$
<p>以下是我的模型:</p>
<pre><code>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)
</code></pre>
<p>以下是我的网址:</p>
<pre><code>urlpatterns = [
url(r'^ofac/', include('ofac_sdn.urls')),
url(r'^admin/', admin.site.urls),
</code></pre>
<p>这就是我的观点。没有创建视图,但我应该看到在这个ofac_sdn表/模型中的输入。在</p>
<pre><code>from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse("<h1> Hi Cohen</h1>")
</code></pre>
<p>问题是我可以从应用程序中看到我的数据库中的记录,但它们不会显示在管理员中。提前谢谢你!在</p>
<p>以下是完整的错误:</p>
<pre><code>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>
</code></pre>