解决django从脚本文件(或其他文件)中导入app中的model时报错xxx.models.DeviceModel doesn‘t declare an explicit app_label

2023-11-19

完整报错:

RuntimeError: Model class xxxx.models.DeviceModel doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

解决方法

这是因为我们把

比如我的文件结构是:

- apps/
	- test_app/ (这个是我注册的app)
		- apps.py
		- model.py

我的app名称叫test_app,同时也在setting.py文件中使用INSTALLED_APPS注册了,那么在外部使用:

from test_app.model import xxModel

就会报错,改为:

from apps.test_app.model import xxModel

就OK了

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

解决django从脚本文件(或其他文件)中导入app中的model时报错xxx.models.DeviceModel doesn‘t declare an explicit app_label 的相关文章

随机推荐