nidHi
nidHi

Reputation: 833

Error while integration a html template and url in django

I am using Django version 1.10.

Below is my urls.py(frontend),

from django.conf.urls import include,url
from django.contrib import admin

urlpatterns = [
   url(r'^webApp/', include('webApp.urls')),
   url(r'^admin/', admin.site.urls),
   url(r'^home/$', 'frontend.views.home', name='home'),
]

Below is my urls.py(webApp),

from django.conf.urls import url

from . import views

urlpatterns = [
    url(r'^$', views.index, name='index'),

]

And below is my views.py,

def home(request):
    return render_to_response('home.html')

Here, frontend is my project name and webApp is my app name. And i have a home.html in my templates folder in frontend.

When I run,

python manage.py runserver 0.0.0.0:8000

I get the following error,

File "/root/frontend/frontend/urls.py", line 22, in <module>
url(r'^home/$', 'frontend.views.home', name='home'),
File "/usr/local/lib/python2.7/dist-packages/django/conf/urls/__init__.py", line 85, in url
raise TypeError('view must be a callable or a list/tuple in the case of include().')
TypeError: view must be a callable or a list/tuple in the case of include()

I don't know what I am doing wrong... Any guidance in the same?

Upvotes: 2

Views: 425

Answers (1)

Filippo Lauria
Filippo Lauria

Reputation: 2064

In the urlpatterns list you are not properly using the function url (you're passing a string as its second argument, but it - in this case - [..] must be a callable [..]).

So... just change 'frontend.views.home' to frontend.views.home (i.e. remove single quotes) and you should be fine.

Upvotes: 2

Related Questions