Django - 在“已安装的应用程序”中添加应用程序名称时出现值错误。

时间:2018-06-10 00:48:28

标签: python django

当我在settings.py文件中的INSTALLED APPS中添加我的应用程序名称时,我收到以下错误,当我从设置中删除我的应用程序名称时将其删除。这有什么问题?

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

1 个答案:

答案 0 :(得分:0)

我遇到了几乎相同的问题。 最后,我发现问题出在应用程序中的models.py,它是由命令“ python manage.py inspectdb> models.py”生成的。 此models.py不是utf-8格式。您可以通过notepad ++打开它,然后更改格式并保存。然后,一切都很好。