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

查看:30
本文介绍了在需要较低 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,使用 sudo python setup.py install 将它安装在我的 OS X 10.9 上.我注意到在 shell 输出中放置了一个新的 django egg:/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

我认为这个错误是因为 /Library/Python/2.7/site-packages/Django-1.4.5-py2.7.egg/ 的蛋中的 global_settings.py尝试配置一个在 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. Remember 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 的粗浅理解告诉我,这不是解决方案,对吧?editlive 不应该尝试使用 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? Shouldn'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?

推荐答案

好的,谢谢大家的意见.你帮助我回答了我的问题并提高了我的基本理解.并非所有对我的问题的评论都是 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 应用程序,重复使用一个 1.4.5 应用程序和一个 1.5.5 应用程序,只要你在 Django 版本 1.6<=version<2.0 中运行它.

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 egg 目录,瞧,一切又正常了.

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天全站免登陆