在我的django项目中,我收集了apps文件夹下的所有应用程序,当我尝试将其包含到settings.py中并运行服务器时,我找不到模块xxx。
我的项目文件夹的结构如下:
myProject
-media
-myProject
--apps
---registration
----__init__.py
----models.py
----views.py
----urls.py
--settings.py
--urls.py
-static
-templates
-manage.py
myProjects下的urls.py:
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'myProject.views.home', name='home'),
url(r'^admin/', include(admin.site.urls)),
url(r'^registration/', include(myProject.apps.registration.urls)),
)
在apps / registration 下的urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
url(r'^registration/$', 'nonsenseprojects.views.registration', name='registration'),
)
settings.py
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'registration', dosen't work
# 'apps.registration', dosen't work
# 'myProject.apps.registration' dosen't work
)
终端错误消息:
> thor@thor:~/Documents/myProjects$ sudo python manage.py runserver
> 127.0.0.1:8008 ImportError: No module named registration
如何在settings.py
中设置应用程序的路径提前谢谢
答案 0 :(得分:0)
如果您希望自己的应用与子文件夹一起使用..请尝试以下
在你的settings.py
所有你需要做的就是
myProject.apps.registration
在apps / registration 下的urls.py
urlpatterns = patterns('myProject.apps.registration.views',
(r'^$', 'Submit_url'),
)
然后导入的最佳方式如
来自myProject.apps.registration.models的导入
<ModelName>