Python Django 导入错误 - 没有名为 django.conf.urls.defaults 的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19962736/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 15:05:21  来源:igfitidea点击:

Django import error - no module named django.conf.urls.defaults

pythondjangographitedjango-1.6

提问by GJain

I am trying to run statsd/graphite which uses django 1.6.

我正在尝试运行使用 django 1.6 的 statsd/graphite。

While accessing graphite URL, I get django module error

访问石墨 URL 时,出现 django 模块错误

File "/opt/graphite/webapp/graphite/urls.py", line 15, in from django.conf.urls.defaults import * ImportError: No module named defaults

文件“/opt/graphite/webapp/graphite/urls.py”,第 15 行,来自 django.conf.urls.defaults import * ImportError: No module named defaults

However, I do not find defaultsdjango package inside /Library/Python/2.7/site-packages/django/conf/urls/

但是,我在里面没有找到默认的django 包/Library/Python/2.7/site-packages/django/conf/urls/

Please help fixing this issue.

请帮助解决这个问题。

采纳答案by Alasdair

django.conf.urls.defaultshas been removed in Django 1.6. If the problem was in your own code, you would fix it by changing the import to

django.conf.urls.defaults已在 Django 1.6 中删除。如果问题出在您自己的代码中,您可以通过将导入更改为

from django.conf.urls import patterns, url, include

However, in your case the problem is in a third party app, graphite. The issue has been fixedin graphite's master branch and version 0.9.14+.

但是,在您的情况下,问题出在第三方应用程序石墨中。该问题在 Graphite 的 master 分支和 0.9.14+ 版本中得到修复。

In Django 1.8+ you can remove patternsfrom the import, and use a list of url()s instead.

在 Django 1.8+ 中,您可以patterns从导入中删除,并使用url()s列表代替。

from django.conf.urls import url, include

回答by Greg Dubicki

If for some reason you don't want to downgrade to Django 1.5.x or upgrade Graphite then you can apply the fixto your older Graphite with:

如果由于某种原因您不想降级到 Django 1.5.x 或升级 Graphite,那么您可以使用以下命令将修复程序应用于旧的 Graphite:

find ./ -type f -exec sed -i -e 's/from\ django\.conf\.urls\.defaults\ import\ \*/from\ django\.conf\.urls\ import\ \*/g' {} \;

..in your <graphite_dir>/webapp/graphitedir.

..在你的<graphite_dir>/webapp/graphite目录中。

This helped me with my Graphite 0.9.12 and Django 1.7(.5).

这对我的 Graphite 0.9.12 和 Django 1.7(.5) 有帮助。

(I also had to do:

(我还必须这样做:

find ./ -type f -exec sed -i -e 's/mimetype\=/content_type\=/g' {} \;
find ./ -type f -exec sed -i -e 's/content_type\=mimetype/content_type\=content_type/g' {} \;

..later on as after I managed to start Graphite some of its features didn't work. Now they work for me but YMMV.)

..后来,在我设法启动 Graphite 之后,它的某些功能不起作用。现在他们为我工作,但 YMMV。)