Solution:
Django 1.10 no longer approves you to seclude views as a string ( 'myapp.views.home'
) in your URL patterns.
The solution is to update your urls.py
to add the view callable. This imply that you have to import the view in your urls.py
. In case your URL patterns don't have names, then now is a good time to include one, since reversing with the dotted python path no longer performs.
from django.conf.urls import include, url
from django.contrib.auth.views import login
from myapp.views import home, contact
urlpatterns = [
url(r'^$', home, name='home'),
url(r'^contact/$', contact, name='contact'),
url(r'^login/$', login, name='login'),
]
In case there are many views, then importing them separately can be in expedient. An alternative is to import the views module from your app.
from django.conf.urls import include, url
from django.contrib.auth import views as auth_views
from myapp import views as myapp_views
urlpatterns = [
url(r'^$', myapp_views.home, name='home'),
url(r'^contact/$', myapp_views.contact, name='contact'),
url(r'^login/$', auth_views.login, name='login'),
]
Note that we have employed as myapp_views
and as auth_views
, which approves us to import the views.py
from multiple apps without them clashing.
This error only imply that myapp.views.home
is not something that can be called, like a function. It is a string in fact at the time your solution performs in django 1.9, notwithstanding it throws a warning saying this will reprove from version 1.10 onwards, which is accurately what has occured. The former solution imports the requires view functions into the script through either from myapp import views as myapp_views
or from myapp.views import home, contact
You may also obtain this error in case you have a name clash of a view and a module. I've got the error at the time i allot my view files underneath views folder, /views/view1.py, /views/view2.py
and imported some model named table.py in view2.py which occoured to be a name of a view in view1.py. So naming the view functions as v_table(request,id)
helped.
The resolution is to update your urls.py
to add the view callable. This imply that you have to import the view in your urls.py
. In case your URL patterns don't have names, then now is a good time to include one, since turn over with the dotted python path no longer performs.
from django.contrib.auth.views import login
from myapp.views import home, contact
urlpatterns = [
url(r'^$', home, name='home'),
url(r'^contact/$', contact, name='contact'),
url(r'^login/$', login, name='login'),
]
In case there are many views, then importing them separately can be difficult. An substitute is to import the views module from your app.
from django.contrib.auth import views as auth_views
from myapp import views as myapp_views
urlpatterns = [
url(r'^$', myapp_views.home, name='home'),
url(r'^contact/$', myapp_views.contact, name='contact'),
url(r'^login/$', auth_views.login, name='login'),
]
Note that we have employed as myapp_views
and as auth_views
, which approves us to import the views.py
from multiple apps without them clashing.