在自己的项目中重用Django应用程序需要较低的django版本 [英] Reusing Django apps in own project wich require a lower django version

查看:178
本文介绍了在自己的项目中重用Django应用程序需要较低的django版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我比较新的django和python,所以我想我在这里缺少一些基础。

I am relatively new to django and python so I guess I am missing some basics here.

我想使用 django-editlive ,因此也 dajaxice 在我的Django 1.6项目/应用程序中。

I want to use django-editlive and therefore also dajaxice in my Django 1.6 project/app.

首先我安装了dajaxice并让它工作(尽管我遇到类似的情况,如下所述...)。然后我从github克隆了django-editlive,将其安装在我的OS X 10.9上,使用 sudo python setup.py install 。我在shell输出中注意到一个新的django蛋被放置: /Library/Python/2.7/site-packages/Django-1.4.5-py2.7.egg / 。在我添加editlive到我的settings.py之后,我收到一个这样的错误:

First I installed dajaxice and got it to work (although I ran into a similar situation as described below...). Then I cloned django-editlive from github, installed it on my OS X 10.9 with sudo python setup.py install. I noticed in the shell output that a new django egg was placed: /Library/Python/2.7/site-packages/Django-1.4.5-py2.7.egg/. After I added editlive to my settings.py I get an error like this:

Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/Django-1.4.5-py2.7.egg/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/Django-1.4.5-py2.7.egg/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/Django-1.4.5-py2.7.egg/django/core/management/__init__.py", line 252, in fetch_command
app_name = get_commands()[subcommand]
File "/Library/Python/2.7/site-packages/Django-1.4.5-py2.7.egg/django/core/management/__init__.py", line 101, in get_commands
apps = settings.INSTALLED_APPS
File "/Library/Python/2.7/site-packages/Django-1.4.5-py2.7.egg/django/utils/functional.py", line 184, in inner
self._setup()
File "/Library/Python/2.7/site-packages/Django-1.4.5-py2.7.egg/django/conf/__init__.py", line 42, in _setup
self._wrapped = Settings(settings_module)
File "/Library/Python/2.7/site-packages/Django-1.4.5-py2.7.egg/django/conf/__init__.py", line 135, in __init__
logging_config_func(self.LOGGING)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/config.py", line 803, in dictConfig
dictConfigClass(config).configure()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/config.py", line 568, in configure
'filter %r: %s' % (name, e))
ValueError: Unable to configure filter 'require_debug_true': Cannot resolve 'django.utils.log.RequireDebugTrue': No module named RequireDebugTrue

我认为这个错误是因为egg中的global_settings.py是 Library / Python / 2.7 / site-packages / Django-1.4.5-py2.7.egg / 其中尝试配置Django 1.6中不存在的过滤器。记住我的应用程序与Django 1.6一起运行。

I figured that this error is because of the global_settings.py in the egg of /Library/Python/2.7/site-packages/Django-1.4.5-py2.7.egg/ which tries to configure a filter which does not exist in Django 1.6 anymore. Remeber that my app runs with Django 1.6.

/Library/Python/2.7/site-packages/Django-1.4.5-py2.7.egg/django/conf/global_settings.py包含:

/Library/Python/2.7/site-packages/Django-1.4.5-py2.7.egg/django/conf/global_settings.py contains:

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
    'require_debug_false': {
        '()': 'django.utils.log.RequireDebugFalse',
    }
},

现在,简单的解决方案当然是删除该过滤器并瞧。但是如果有一个更加微妙的不兼容呢?在Django 1.6项目中,如何正确地重复使用需要 Django> = 1.3,< = 1.4.5 的应用程序?我对virtualenv的谦虚的理解告诉我,这不是解决方案,对吧?尝试使用Django 1.6尝试使用Django 1.6或许可能会失败,但至少不要安装并尝试使用旧版本的Django?如果virtualenv是解决方案,我的应用程序如何知道其他应用程序应该运行在较旧的Django版本中?现在可以看出,我在这里缺乏一些基础知识。感谢您帮助我!

Now the simple solution is of course to remove that filter and voila. But what if there was a more delicate incompatibility? How do I correctly reuse an app the requires Django>=1.3,<=1.4.5 in my Django 1.6 project? My humble understanding of virtualenv tells me that this is not the solution, right? Shoudn't editlive try to use Django 1.6 and maybe fail horribly but at least not install and try to use an older version of Django? If virtualenv is the solution, how does my app know that the other app should run in the older Django version? You can figure now that I lack some basics here. Thanks for helping me out!

推荐答案

好的,谢谢所有的意见。你帮我回答我的问题,提高我的基本了解。并非所有对我的问题的意见都是100%正确。我必须强调,Django的次要版本都是向后兼容的,除非在发行说明中另有说明,否则不作为。请阅读 Django发布流程

OK, thanks for all the comments. You helped me to answer my questions and to improve my basic understanding. Not all of the comments to my questions are 100% correct. I have to stress that Django minor releases are all backwards compatibel unless otherwise stated in the release notes and except the deprecations. Please read Django release process.

所以基本上为Django 1.4.5或1.5.5编写的代码应该仍然运行在Django 1.6之下,你也应该可以混合使用。所以可以编写一个Django 1.6应用程序,只要您在Django 1.6版本< 2.0版中运行,就可以重用一个1.4.5应用程序和一个1.5.5应用程序。

So basically all code written for Django 1.4.5 or 1.5.5 should still run under Django 1.6, and you should also be able to mix it. So it is possible to write a Django 1.6 app, reuse one 1.4.5 app and one 1.5.5 app as long as you run it in a Django version 1.6<=version<2.0.

我的案例中的问题是editlive,它定义了对Django> = 1.3,<= 1.4.5的依赖,导致安装工具将Django 1.4.5下载并安装到我的系统上。我没有意识到,我自己的应用程序从那时开始使用Django 1.4.5。之后抛出的错误是由于在我自己的应用程序中使用了 django.utils.log.RequireDebugTrue 。此过滤器仅在Django 1.5中引入,因此不会在1.4.5之下运行。

The issue in my case was editlive defining its dependency to Django>=1.3,<=1.4.5 which caused the setup tool to download and install Django 1.4.5 onto my system. What I did not realize is that my own application started to use Django 1.4.5 from that point on. The error thrown afterwards was due to the usage of django.utils.log.RequireDebugTrue in my own app. This filter was only introduced in Django 1.5 and thus would not run under 1.4.5.

我只需删除整个1.4.5的蛋目录,瞧,一切都正常

I just had to delete the entire 1.4.5 egg directory and voila, everything works again.

我还没有测试editlive的功能,但至少在编译时间中没有任何错误。

I did not test the functionality of editlive yet, but at least there aren't any errors at 'compile time'.

这篇关于在自己的项目中重用Django应用程序需要较低的django版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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