问题描述
在升级到 Django 1.7 时,我从 ./manage.py
On upgrading to Django 1.7 I'm getting the following error message from ./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
有什么问题,我该如何解决?
What's the problem and how do I resolve it?
推荐答案
问题在于,随着 Django 1.7 中应用程序的更改,应用程序需要具有唯一标签.
The problem is that with the changes to apps in Django 1.7, apps are required to have a unique label.
默认情况下,应用标签是包名称,所以如果你有一个与你的应用模块同名的包(在本例中为foo
),你会点击这个错误.
By default the app label is the package name, so if you've got a package with the same name as one of your app modules (foo
in this case), you'll hit this error.
解决方案是覆盖应用的默认标签,并通过将其添加到 __init__.py
来强制加载此配置.
The solution is to override the default label for your app, and force this config to be loaded by adding it to __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'
参见 https://docs.djangoproject.com/en/1.7/ref/applications/#for-application-authors
这篇关于如何解决“django.core.exceptions.ImproperlyConfigured:应用程序标签不唯一,重复:foo"在 Django 1.7 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!