{% optional_logout request user %}
来源:5-5 apiview方式实现商品列表页-2
折叠幸福
2018-05-02
运行出现这个错误
TypeError at /goods/
__str__ returned non-string (type NoneType)
Request Method:
GET
Request URL:
http://127.0.0.1:8000/goods/
Django Version:
1.11.3
Exception Type:
TypeError
Exception Value:
__str__ returned non-string (type NoneType)
Exception Location:
/Users/bill/demo/VueShop/lib/python3.6/site-packages/django/utils/functional.py in inner, line 239
Python Executable:
/Users/bill/demo/VueShop/bin/python3.6
Python Version:
3.6.3
Python Path:
['/Users/bill/Documents/GitHub/MxShop/extra_apps',
'/Users/bill/Documents/GitHub/MxShop/apps',
'/Users/bill/Documents/GitHub/MxShop',
'/Users/bill/Documents/GitHub/MxShop',
'/Applications/PyCharm.app/Contents/helpers/pydev',
'/Users/bill/Documents/GitHub/MxShop',
'/Users/bill/Documents/GitHub/MxShop/apps',
'/Users/bill/Documents/GitHub/MxShop/extra_apps',
'/Applications/PyCharm.app/Contents/helpers/pydev',
'/Users/bill/Library/Caches/PyCharm2017.3/cythonExtensions',
'/Users/bill/demo/VueShop/lib/python36.zip',
'/Users/bill/demo/VueShop/lib/python3.6',
'/Users/bill/demo/VueShop/lib/python3.6/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6',
'/Users/bill/demo/VueShop/lib/python3.6/site-packages',
'/Applications/PyCharm.app/Contents/helpers/pycharm_matplotlib_backend']
Server time:
星期三, 2 五月 2018 15:52:38 +0800
Error during template rendering
In template /Users/bill/demo/VueShop/lib/python3.6/site-packages/rest_framework/templates/rest_framework/base.html, error at line 49
__str__ returned non-string (type NoneType)
39
<span>
40
{% block branding %}
41
<a class='navbar-brand' rel="nofollow" href='http://www.django-rest-framework.org'>
42
Django REST framework
43
</a>
44
{% endblock %}
45
</span>
46
<ul class="nav navbar-nav pull-right">
47
{% block userlinks %}
48
{% if user.is_authenticated %}
49
{% optional_logout request user %}
50
{% else %}
51
{% optional_login request %}
52
{% endif %}
53
{% endblock %}
54
</ul>
55
</div>
56
</div>
57
{% endblock %}
58
59
<div class="container">
Traceback Switch to copy-and-paste view
1回答
-
bobby
2018-05-05
__str__ returned non-string (type NoneType) 这个错误很明显了 你的某个model 定义的__str__方法返回了None值 你在返回model的某个字段的时候如果这个字段能为空 你最好自己先判断一下这个值是否为None
00
Python前后端分离开发Vue+Django REST framework实战
2873 学习 · 2461 问题
相似问题