我在django中收到导入错误。我的主要urls.py设置文件位于main/main/urls.py
我的模块或应用位于main/apps/builder/urls.py
。
追溯错误
ImportError at /
No module named apps.builder.urls
Request Method: GET
Request URL: ***************
Django Version: 1.4
Exception Type: ImportError
Exception Value:
No module named apps.builder.urls
Exception Location: /usr/lib/python2.6/site-packages/django/utils/importlib.py in import_module, line 35
Python Executable: /usr/bin/python26
Python Version: 2.6.0
Python Path:
['/home/pycode/main',
'/usr/lib/python26.zip',
'/usr/lib/python2.6',
'/usr/lib/python2.6/plat-linux2',
'/usr/lib/python2.6/lib-tk',
'/usr/lib/python2.6/lib-old',
'/usr/lib/python2.6/lib-dynload',
'/usr/lib/python2.6/site-packages']
Server time: Tue, 12 Jun 2012 12:39:17 -0500
主/主/ urls.py
from django.conf.urls import patterns, include, url
urlpatterns = patterns('',
url(r'^$', include('main.apps.builder.urls')),
)
答案 0 :(得分:3)
您的apps
模块必须低于main/main
,否则您必须确保apps
文件夹位于sys.path
,最好设置PYTHONPATH。
答案 1 :(得分:0)
您是否在settings.py文件中将其添加到INSTALLED_APPS
?
https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
同样ramdaz建议每个目录都需要一个__init__.py
文件,即使它是空的。