作者: Jim Wang 公众号: 巴博萨船长

摘要:我们在尝试安装调试graphite webapp时,或者使用django制作网站时会遇见此问题:错误:no module named django.conf.urls.defaults,本文讨论如何解决该问题。

Abstract: When we try to install and debug the graphite webapp, or use django to make a website, we will encounter this problem: error: no module named django.conf.urls.defaults, this article discusses how to solve this problem.

作者: Jim Wang 公众号: 巴博萨船长

问题

我们在尝试安装调试graphite webapp时,或者使用django制作网站时会遇见此问题。或者类似的问题.

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

解决方案

原因在于:Django 1.6 时改变了模块结构,原先的defaults模块被去除了。为了解决这一问题你有两种方式。

1:回滚到1.5.x版本上

2:找到代码问题行,将此行改为

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

相信能解决你的问题。

如果你是在调试暗转graphite webapp时遇见此问题,下列的Python脚本fixerrorNomodule.py能够一次性修复所有的有问题的模块。代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import re
files = ["/opt/graphite/webapp/graphite/urls.py",
"/opt/graphite/webapp/graphite/urls.py",
"/opt/graphite/webapp/graphite/render/urls.py",
"/opt/graphite/webapp/graphite/cli/urls.py",
"/opt/graphite/webapp/graphite/composer/urls.py",
"/opt/graphite/webapp/graphite/metrics/urls.py",
"/opt/graphite/webapp/graphite/browser/urls.py",
"/opt/graphite/webapp/graphite/account/urls.py",
"/opt/graphite/webapp/graphite/dashboard/urls.py",
"/opt/graphite/webapp/graphite/whitelist/urls.py",
"/opt/graphite/webapp/graphite/graphlot/urls.py",
"/opt/graphite/webapp/graphite/version/urls.py",
"/opt/graphite/webapp/graphite/events/urls.py"]
files2= ["/opt/graphite/webapp/graphite/urls.py"]
str = 'from django.conf.urls.defaults import *\n'
for file in files:
print file
f = open(file, "r+")
flists = f.readlines()
print len(flists),
for i in range(len(flists)):
if flists[i] == str:
print flists[i]
flists[i] = "from django.conf.urls import patterns, url, include \n"
else:
pass
f = open(file, "w+")
f.writelines(flists)
f.close()

使用方法

1
python scirpte name: fixerrorNomodule.py

欢迎大家关注本人个人公众号评论。才疏学浅,欢迎交流提意见彼此提高。需要声明一下51cto博客作者zuiwuxin就是作者本人,所以不存在版权问题。以后该博客将作为个人文章的主要发布地。


版权声明:
文章首发于 Jim Wang's blog , 转载文章请务必以超链接形式标明文章出处,作者信息及本版权声明。