Reputation: 8531
For some reason the webapp I created, cannot find the template. I tried also to place the html file into several different location, but it still won't find it. As of now I have placed my template director at the following location C:\xampp\htdocs\django_proj\templates\
. Do someone else know what the problem could be.
I have another webapp in this django project. The model and view, look almost the same, however that webapp can find the templates.
/webapp/models.py
from django.db import models
class Profile(models.Model):
name = models.CharField(max_length=255)
age = models.IntegerField()
added_at = models.DateTimeField(auto_now_add=True)
/webapp/views.py
from django.views.generic.list_detail import object_list
from models import Profile
def profile_list(request):
return object_list(request,
queryset=Profile.objects.all(),
template_name='/webapp/list.html',
template_object_name='profiles')
/webapp/urls.py
from django.conf.urls.defaults import *
import views
urlpatterns = patterns('',
url(r'^list/$', views.profile_list, name='profile_list'),
)
/urls.py
from django.conf.urls import *
urlpatterns = patterns('',
(r'^webapp/', include('webapp.urls')),
)
/templates/webapp/list.html
<html>
<body>
Test
</body>
</html>
Error message
TemplateDoesNotExist at /webapp/list/
/webapp/list.html
Request Method: GET
Request URL: http://localhost:8000/webapp/list/
Django Version: 1.4 pre-alpha
Exception Type: TemplateDoesNotExist
Exception Value:
/webapp/list.html
Exception Location: c:\tools\python27\lib\site-packages\django\template\loader.py in find_template, line 138
Python Executable: c:\tools\python27\python.exe
Python Version: 2.7.2
Python Path:
['C:\\xampp\\htdocs\\webnotes',
'c:\\tools\\python27\\lib\\site-packages\\pip-1.0.2-py2.7.egg',
'C:\\Windows\\system32\\python27.zip',
'c:\\tools\\python27\\DLLs',
'c:\\tools\\python27\\lib',
'c:\\tools\\python27\\lib\\plat-win',
'c:\\tools\\python27\\lib\\lib-tk',
'c:\\tools\\python27',
'c:\\tools\\python27\\lib\\site-packages']
Server time: Thu, 12 Jan 2012 19:33:48 +0100
Template-loader postmortem
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
Upvotes: 1
Views: 2336
Reputation: 45224
Your template name contains the aboslute path /webapp/list.html
. Try making it a relative path webapp/list.html
so that os.path.join(.)
handles path concatenation as intended.
Try this:
def profile_list(request):
return object_list(request,
queryset=Profile.objects.all(),
template_name='webapp/list.html', # removed slash here.
template_object_name='profiles')
Upvotes: 5
Reputation: 674
Try to change your url pattern on /webapp/urls.py from:
url(r'^list/$', views.profile_list, name='profile_list'),
to
url(r'^webapp/list/$', views.profile_list, name='profile_list'),
Upvotes: 0