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
Django import error - no module named django.conf.urls.defaults
提问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.defaults
has 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 patterns
from 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/graphite
dir.
..在你的<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。)