Django外部库和应用程序名称冲突 [英] Django external library and app name conflict

查看:133
本文介绍了Django外部库和应用程序名称冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个django应用程序'my_app'。现在添加了一个恰好具有相同名称并需要添加到INSTALLED_APPS的外部库。

  src 
|
- apps
|
--- ** my_app **


外部库
|
__ ** my_app **
|
__some_path
|
__ new_module

Django遵循旧路径并吐出

 错误:没有名为my_app.some_path.new_module的模块

因为它看起来错误的文件夹。

  INSTALLED_APPS =(
...
apps.my_app
my_app.some_path.new_module
...

注意:INSTALLED_APPS中的应用程序顺序不会区别。从INSTALLED_APS删除apps.my_app也没有任何区别。



当我尝试输入

  import my_app 

pycharm auto建议apps.my_app



有没有办法解决这个问题,而不是重命名一个应用程序?

解决方案

对于即将推出的Django 1.7版本,它使用应用程序注册表。您可以为每个应用设置标签,以引用给他们用不同的名字。


Have a django app 'my_app'. Now added an external library that happens to have the same name and needs to be added to INSTALLED_APPS.

src
 |
 -- apps
      |
      --- **my_app**


external libraries
         |
          __ **my_app**
               |
                __some_path
                      |
                       __ new_module

Django follows the old path and spits out

Error: No module named my_app.some_path.new_module

because it is looking in the wrong folder.

INSTALLED_APPS = (
    ...
    apps.my_app
    my_app.some_path.new_module
    ...
)

Note: order of apps in INSTALLED_APPS makes no difference. Removing apps.my_app from INSTALLED_APS also made no difference.

When I try to type

import my_app

pycharm auto suggests apps.my_app

Is there any way to resolve this without renaming one of the apps?

解决方案

Well, brace yourself for the upcoming Django 1.7 release which solves such app conflicts in an elegant manner using an "app registry". You can set a label for each app to refer to them with a different name.

这篇关于Django外部库和应用程序名称冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆