在運行項目,準備遷移時出現的如下錯誤:
Traceback (most recent call last):
File "C:\py3_env\lib\site-packages\django\apps\config.py", line 107, in create
entry = module.default_app_config
AttributeError: module 'restful' has no attribute 'default_app_config'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\software\PyCharm 2017.3.3\helpers\pycharm\django_manage.py", line 43, in <module>
run_module(manage_file, None, '__main__', True)
File "c:\python36\Lib\runpy.py", line 205, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "c:\python36\Lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "c:\python36\Lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:/SELF_MEDIA_PLATFORM/self_media_dev\manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\py3_env\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\py3_env\lib\site-packages\django\core\management\__init__.py", line 357, in execute
django.setup()
File "C:\py3_env\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\py3_env\lib\site-packages\django\apps\registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "C:\py3_env\lib\site-packages\django\apps\config.py", line 110, in create
return cls(entry, module)
File "C:\py3_env\lib\site-packages\django\apps\config.py", line 40, in __init__
self.path = self._path_from_module(app_module)
File "C:\py3_env\lib\site-packages\django\apps\config.py", line 73, in _path_from_module
"with a 'path' class attribute." % (module, paths))
django.core.exceptions.ImproperlyConfigured: The app module <module 'restful' (namespace)> has multiple filesystem locations (['C:\\***\\restful', 'C:/***\\restful']); you must configure this app with an AppConfig subclass with a 'path' class attribute.
解決方案:
出現這種錯誤的原因之一是因爲在Django工程路徑中找不到此app的路徑,需要在此app下新建一個包文件__init__.py 即可解決此問題。