在升级到Django 1.7时,我收到以下错误消息 ./manage.py
./manage.py
$ ./manage.py Traceback (most recent call last): File "./manage.py", line 16, in <module> execute_from_command_line(sys.argv) File "/home/johnc/.virtualenvs/myproj-django1.7/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 427, in execute_from_command_line utility.execute() File "/home/johnc/.virtualenvs/myproj-django1.7/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 391, in execute django.setup() File "/home/johnc/.virtualenvs/myproj-django1.7/local/lib/python2.7/site-packages/django/__init__.py", line 21, in setup apps.populate(settings.INSTALLED_APPS) File "/home/johnc/.virtualenvs/myproj-django1.7/local/lib/python2.7/site-packages/django/apps/registry.py", line 89, in populate "duplicates: %s" % app_config.label) django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: foo
有什么问题,我该如何解决?
问题在于,随着Django 1.7中应用程序的更改,要求应用程序具有唯一标签。
默认情况下,应用程序标签为程序包名称,因此,如果你具有与你的应用程序模块之一相同名称的程序包(foo在本例中),则会遇到此错误。
foo
解决方案是覆盖应用程序的默认标签,并通过将其添加到来强制加载此配置__init__.py。
__init__.py
# foo/apps.py from django.apps import AppConfig class FooConfig(AppConfig): name = 'full.python.path.to.your.app.foo' label = 'my.foo' # <-- this is the important line - change it to anything other than the default, which is the module name ('foo' in this case)
和
# foo/__init__.py default_app_config = 'full.python.path.to.your.app.foo.apps.FooConfig'