python - django - import error: no module named views -


i've been racking brains , can't figure out why there should import error when 'views' imported. following message when visit index page:

" request method: request url:    http://127.0.0.1:8000/moments/ django version: 1.6.1 exception type: importerror exception value:     no module named views exception location: c:\python27\lib\site-packages\django\utils\importlib.py in import_module, line 40 " 

here urls.py

from django.conf.urls import patterns, url  moments_app import views  urlpatterns = patterns('',     url(r'^$', "views.index", name='index'),     url(r'^$', "views.choose_dataset", name='choose'),     url(r'^get_moments/', "views.get_moments", name='get_moments'),     url(r'^learn/$', "views.learn", name='learn'),     url(r'^(?p<moment_id>\d+)/$', "views.detail", name='detail'),  ) 

i have module named views in moments_app folder. also, moments_app in path. have ideas might causing this?

you prefixed route names relative module name. use absolute name:

urlpatterns = patterns('',     url(r'^$', "moments_app.views.index", name='index'),     url(r'^$', "moments_app.views.choose_dataset", name='choose'),     url(r'^get_moments/', "moments_app.views.get_moments", name='get_moments'),     url(r'^learn/$', "moments_app.views.learn", name='learn'),     url(r'^(?p<moment_id>\d+)/$', "moments_app.views.detail", name='detail'), ) 

or better still, use first argument specify full module path:

urlpatterns = patterns('moments_app.views',     url(r'^$', "index", name='index'),     url(r'^$', "choose_dataset", name='choose'),     url(r'^get_moments/', "get_moments", name='get_moments'),     url(r'^learn/$', "views.learn", name='learn'),     url(r'^(?p<moment_id>\d+)/$', "detail", name='detail'), ) 

although combination of 2 allowed:

urlpatterns = patterns('moments_app',     url(r'^$', "views.index", name='index'),     url(r'^$', "views.choose_dataset", name='choose'),     url(r'^get_moments/', "views.get_moments", name='get_moments'),     url(r'^learn/$', "views.learn", name='learn'),     url(r'^(?p<moment_id>\d+)/$', "views.detail", name='detail'), ) 

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -