Django 错误 TypeError: unsupported operand type(s) for PosixPath and str
程序员文章站
2022-03-05 12:20:47
...
在学习Django模版的时候,遇到了如下错误:
aaa@qq.com:~/Detection# python3 manage.py runserver 0.0.0.0:8006
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/dist-packages/Django-3.1a1-py3.6.egg/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/dist-packages/Django-3.1a1-py3.6.egg/django/core/management/__init__.py", line 345, in execute
settings.INSTALLED_APPS
File "/usr/local/lib/python3.6/dist-packages/Django-3.1a1-py3.6.egg/django/conf/__init__.py", line 77, in __getattr__
self._setup(name)
File "/usr/local/lib/python3.6/dist-packages/Django-3.1a1-py3.6.egg/django/conf/__init__.py", line 64, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python3.6/dist-packages/Django-3.1a1-py3.6.egg/django/conf/__init__.py", line 171, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/root/Detection/Detection/settings.py", line 57, in <module>
'DIRS': [BASE_DIR+"/templates",],
TypeError: unsupported operand type(s) for +: 'PosixPath' and 'str'
- 这是一个类型错误,意思是说Python无法识别你使用的信息,Python发现你使用了一个PosixPath的变量要与str类型的相关联,“+”这个符号有相加的作用也有连接的作用,然后Python就不知道如何去处理了。
- 因此,可调用***str()函数***,它让Python将非字符串值表示为字符串。
更改后的代码:
参考博文:
https://blog.csdn.net/IT_csdn/article/details/84844532
https://blog.csdn.net/qq_27508477/article/details/106801491
上一篇: Java Spring Cloud Alibaba-RocketMQ:(一)RocketMQ 介绍以及基本使用
下一篇: [机器学习实战-ch09]TypeError: unsupported operand type(s) for /: 'map' and 'int'
推荐阅读
-
小白入门常见报错:TypeError: unsupported operand type(s) for +: ‘int‘ and ‘str‘ 萌新踩雷!!!
-
Django项目debug--TypeError: unsupported operand type(s) for /: ‘str‘ and ‘str‘,分析与解决
-
TypeError: unsupported operand type(s) for /: 'NoneType' and 'NoneType'
-
TypeError: unsupported operand type(s) for +: 'getset_descriptor' and 'int'
-
Django 错误 TypeError: unsupported operand type(s) for PosixPath and str
-
[机器学习实战-ch09]TypeError: unsupported operand type(s) for /: 'map' and 'int'