本文介绍了如何解决“django.core.exceptions.ImproperlyConfigured:应用程序标签不是唯一的,重复的:foo”在Django 1.7?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在升级到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

有什么问题,如何解决

推荐答案

问题是,随着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'

请参见

这篇关于如何解决“django.core.exceptions.ImproperlyConfigured:应用程序标签不是唯一的,重复的:foo”在Django 1.7?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 17:57