我在导入另一个urlpatterns
.
python manage.py shell
->工作正常,但是当我尝试从以下位置导入它时from bar.urls import urlpatterns
Django 找不到:“没有名为 bar.urls 的模块”。bar
foo/foo/urls.py
tree ~/workdir/foo
foo
├── foo
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── local_db
│ │ └── foo.db
│ ├── settings.py
│ ├── urls.py
│ ├── wsgi.py
├── __init__.py
├── manage.py
├── bar
│ ├── __init__.py
│ ├── models.py
│ ├── baz
│ │ ├── __init__.py
│ │ ├── __init__.pyc
│ │ ├── baz_interface.py
│ │ ├── test.py
│ ├── templates
│ │ └── index.html
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── README.md
└── requirements.txt
5 directories, 28 files
foo/urls.py
from django.conf.urls import patterns, include, url
urlpatterns = patterns('',
(r'^test/', include('foo.bar.urls')),
)
# this will fail too :
# 1.
# from foo.bar.urls import urlpatterns as test
# urlpatterns += test
# 2.
# from bar.urls import urlpatterns as test
# urlpatterns += test
# 3.
#urlpatterns = patterns('',
# (r'^test/', include('bar.urls')),
#)
bar/urls.py
from django.conf.urls import patterns, include, url
urlpatterns = patterns('',
url(r'^$', 'foo.bar.views.viewname', name='viewname'),
)
我Django 1.4.3
在Python 2.7.3
virtualenv 中运行。
bar
在我的INSTALLED_APPS
.
~/workdir/foo/
在我的 python 路径中。
我怎样才能urlpattern
从工作中导入foo/foo/urls.py
?
谢谢你。