98

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.

qwerty_so
  • 35,448
  • 8
  • 62
  • 86
GJain
  • 5,025
  • 6
  • 48
  • 82

3 Answers3

198

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
Alasdair
  • 298,606
  • 55
  • 578
  • 516
  • Check also if you have set ROOT_URLCONF in your settings.py! This variable has to also be adapted. In my case it was ROOT_URLCONF = 'urls' and had to be changed to ROOT_URLCONF = 'app.urls' – lszrh Mar 10 '14 at 10:26
  • patterns has been removed. You can directly use a python list to add urls instead of using patterns. – Akshay Hazari Aug 03 '17 at 08:36
  • @Alasdair Was working with a code from django 1.6 and found the defaults replacement here. Just was adding to the answer. So that someone else could find all help at one place. – Akshay Hazari Aug 03 '17 at 08:47
3

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.)

Greg Dubicki
  • 5,983
  • 3
  • 55
  • 68
  • 1
    Thanks, this still appears to be the case in the current iteration of this software! Your fixes work well for me in Graphite 0.9.12 and Django 1.6.1! – Andrew White May 25 '15 at 14:17
0

go to the file location where you have installed python. open cmd on that path and then install django with command >> pip install django

Then cross check on python shell with import django(which should do nothing) or simply use the command >> python -m django --version

it will simply give you version enter image description here

enter image description here

kate.5
  • 1
  • 3