views:

48

answers:

3

I have tried to get this to work a million times. I have lef it alone for a week and come back. I have Googled and read every post pertaining to this. I have let insecure morons belittle in messages groups without ever finding the answer. I just want this to work. When I am following along in part three of the the Django tutorial, I get to the part where you make the template for the index page, and when I go to check it in the browser, it comes up with TemplateDoesNotExist at /polls/. I have checked file ownership, moved it all around, always changing the TEMPLATES_DIR in setting.py. I have pipe'd the contents of the file to cat to make sure it works. I have scarificed animals to strange Gods to get this to work. I turn to you now. I am sure it is the stupidest thing ever, I have very little doubt about this. I just want it to work.

I am not sure what parts of the code/traceback you want/need here, let me know I will post them. I am doing this on Ubuntu 10.10

EDIT

From settings.py:

TEMPLATE_DIRS = ( "home/kevin/first/tutorial/temps" )

This used to live in ~, but I moved into the project folder thinking it would help.

Structure(leaving out all complied python files): ~/first/tutorial/: init.py, manage.py, polls, settings.py, temps, tut.db, urls.py

temps: index.html

polls: admin.py, init.py, models.py, tests.py, views.py,

A: 

Some things to check:

Do you use an absolute path to specify the template directory in settings.py?

Did you put the template directly into the TEMPLATE_DIR directory, or did you make a polls subfolder to put the template in?

dvcolgan
I used an absolute path, and I made a polls folder in the directory under TEMPLATE_DIR
Kevin
+1  A: 
>>> TEMPLATE_DIRS = ( "home/kevin/first/tutorial/temps" )
>>> print TEMPLATE_DIRS
home/kevin/first/tutorial/temps
>>> type(TEMPLATE_DIRS)
<type 'str'>

This is a string, not a tuple.

TEMPLATE_DIRS = ( "home/kevin/first/tutorial/temps", )

That is a tuple. A little bit of a Python gotcha.

Furthermore, use an absolute path rather than a relative path.

brianz
Like I said, it was going to be something like this, thank you so much for your help and your clear, concise explanation
Kevin
A: 

First off, and this might not be relevant to your problem, but it's good practice to not use absolute paths in your files. I always have the following in my settings.py:

PROJECT_ROOT = os.path.realpath(os.path.dirname(__file__))

TEMPLATE_DIRS = (
    os.path.join(PROJECT_ROOT, 'templates'),
)

You should always have a comma at the end of an element in your tuple, even if it is the only one or the last one, so that Python actually considers it to be a tuple and not evaluate to any other type.

You should also make sure that your TEMPLATE_LOADERS setting contains or looks like this:

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
)

If that doesn't fix it (you should still keep the above in regardless), the problem is most likely related to the template you're rendering to. Confirm that the string of the template you're using in the view corresponds correctly to the relative path of the template within your templates directory. In other words, if the template string is 'polls/index.html' in your view, ensure that the file is actually located at templates/polls/index.html.

Pewpewarrows
Thank you for this advice, I am going to start using it going forward
Kevin