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

萝らか妹 提交于 2019-11-28 16:56:01

问题


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

While accessing graphite URL, I get django module error

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

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

Please help fixing this issue.


回答1:


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

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 fixed in graphite's master branch and version 0.9.14+.

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

from django.conf.urls import url, include



回答2:


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

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.

This helped me with my Graphite 0.9.12 and 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.)



来源:https://stackoverflow.com/questions/19962736/django-import-error-no-module-named-django-conf-urls-defaults

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!