Django -在'INSTALLED APPS'中添加应用名称时出现值错误

zxlwwiss  于 2023-02-14  发布在  Go
关注(0)|答案(1)|浏览(164)

当我在www.example.com文件内的已安装应用程序中添加我的应用程序名称时settings.py,出现以下错误,当我从设置中删除我的应用程序名称时,错误被删除。

Unhandled exception in thread started by <function check_errors. 
<locals>.wrapper at 0x0000007BFA7BB598>
Traceback (most recent call last):
File "C:\Users\postgres\AppData\Local\Programs\Python\Python36\lib\site- 
packages\django\utils\autoreload.py", line 227, in wrapper
fn(*args, **kwargs)
File "C:\Users\postgres\AppData\Local\Programs\Python\Python36\lib\site- 
packages\django\core\management\commands\runserver.py", line 117, in 
inner_run autoreload.raise_last_exception()
File "C:\Users\postgres\AppData\Local\Programs\Python\Python36\lib\site- 
packages\django\utils\autoreload.py", line 250, in raise_last_exception
six.reraise(*_exception)
File "C:\Users\postgres\AppData\Local\Programs\Python\Python36\lib\site- 
packages\django\utils\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "C:\Users\postgres\AppData\Local\Programs\Python\Python36\lib\site- 
packages\django\utils\autoreload.py", line 227, in wrapper
fn(*args, **kwargs)
File "C:\Users\postgres\AppData\Local\Programs\Python\Python36\lib\site- 
packages\django\__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\postgres\AppData\Local\Programs\Python\Python36\lib\site- 
packages\django\apps\registry.py", line 108, in populate
app_config.import_models()
File "C:\Users\postgres\AppData\Local\Programs\Python\Python36\lib\site- 
packages\django\apps\config.py", line 202, in import_models
self.models_module = import_module(models_module_name)

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 674, in exec_module
File "<frozen importlib._bootstrap_external>", line 781, in get_code
File "<frozen importlib._bootstrap_external>", line 741, in source_to_code
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ValueError: source code string cannot contain null bytes
3vpjnl9f

3vpjnl9f1#

我也遇到过类似的问题,最后我发现问题出在models.py应用程序中的www.example.com,是由命令“pythonmanage.pyinspectdb〉models.py”生成的,这个models.py不是utf-8格式,你可以用记事本++打开它,更改格式并保存,然后就可以了。

相关问题