tags:

views:

192

answers:

5

My local machine is running with Python 2.5 and Nginx on Ubuntu 8.10, with Django builded from latest development trunk.

For every url I requested, it thrown out:

TemplateDoesNotExist at /appname/path
appname/template_name.html

Django tried loading these templates, in this order:
* Using loader django.template.loaders.filesystem.function:
* Using loader django.template.loaders.app_directories.function: 

TEMPLATE_DIRS   ('/usr/lib/python2.5/site-packages/projectname/templates',)

Is it looking for "/usr/lib/python2.5/site-packages/projectname/templates/appname/template_name.html" in this case? The weird thing is this file DOES existed on disk. Why it couldn't locate it?

I run the same application on a remote server with Python 2.6 on Ubuntu 9.04 without such problem. Other settings are the same.

Is there anything misconfigured on my local machine or what could possibly caused such errors that I should investigate into?

EDIT

In my settings.py, I have specified:

SETTINGS_PATH = os.path.normpath(os.path.dirname(__file__))
# Find templates in the same folder as settings.py.
TEMPLATE_DIRS = (
    os.path.join(SETTINGS_PATH, 'templates'),
)

It shoule be looking for the following files

/usr/lib/python2.5/site-packages/projectname/templates/appname1/template1.html
/usr/lib/python2.5/site-packages/projectname/templates/appname1/template2.html
/usr/lib/python2.5/site-packages/projectname/templates/appname2/template3.html
...

All the above files are EXISTED on disk.

SOLVED

It works now after I tried "chown -R www-data:www-data /usr/lib/python2.5/site-packages/projectname/*"

It's strange. I dont need to do this on the remote server to make it work.

A: 

Just a hunch, but check out this article on Django template loading. In particular, make sure you have django.template.loaders.app_directories.Loader in your TEMPLATE_LOADERS list.

Peter Rowell
A: 

Check that your templates.html are in /usr/lib/python2.5/site-packages/projectname/templates dir.

Juanjo Conti
+1  A: 

First solution:

This settings TEMPLATE_DIRS = ( os.path.join(SETTINGS_PATH, 'templates'), ) means that django will look at the templates from templates/ directory under your project.

Assuming your django project is located at /usr/lib/python2.5/site-packages/projectname/ then with your settings django will look for the templates under /usr/lib/python2.5/site-packages/projectname/templates/

So in that case we want to move our templates to be structured like this:

/usr/lib/python2.5/site-packages/projectname/templates/template1.html
/usr/lib/python2.5/site-packages/projectname/templates/template2.html
/usr/lib/python2.5/site-packages/projectname/templates/template3.html

Second solution:

If that still doesn't work and assuming that you have the apps configured in settings.py like this:

INSTALLED_APPS = (
    'appname1',
    'appname2',
    'appname3',
)

By default django will load the templates under templates/ directory under every installed apps. So with your directory structure, we want to move our templates to be like this:

/usr/lib/python2.5/site-packages/projectname/appname1/templates/template1.html
/usr/lib/python2.5/site-packages/projectname/appname2/templates/template2.html
/usr/lib/python2.5/site-packages/projectname/appname3/templates/template3.html

Hope that helps.

jpartogi
@jpartogi, I tried both approaches but neither works. I even tried to use absolute path to template in render_to_response() argument but still didn't work.
jack
Is your django project under `/usr/lib/python2.5/site-packages/projectname/`?
jpartogi
@jpartogi, yes, all installed apps are under /usr/lib/python2.5/site-packages/projectname/appname1, ...
jack
Can you please edit your original post and paste the settings.py. Excluding the DB Config :-d. Thanks.
jpartogi
+1  A: 

Check permissions on templates and appname directories, either with ls -l or try doing an absolute path open() from django.

kibitzer
A: 

It works now after I tried

chown -R www-data:www-data /usr/lib/python2.5/site-packages/projectname/*

It's strange. I dont need to do this on the remote server to make it work.

Also, I have to run the following command on local machine to make all static files accessable but on remote server they are all "root:root".

chown -R www-data:www-data /var/www/projectname/*

Local machine runs on Ubuntu 8.04 desktop edition. Remote server is on Ubuntu 9.04 server edition.

Anybody knows why?

jack