user2988464 user2988464 - 4 months ago 16
Python Question

Django tuple checking: TEMPLATE_DIRS should be tuple?

I'm trying Django 1.7.

This is my TEMPLATE_DIRS setting:

TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__), 'templates').replace('\\', '/')
)


which is fine for Django 1.6, but doesn't work for Django 1.7.

Can someone explains this?
Thx!!

Answer

You need a trailing , for it to be a tuple, see below, the last ,

TEMPLATE_DIRS = (
    os.path.join(os.path.dirname(__file__), 'templates').replace('\\', '/'),
)

When there's a single element in the tuple you need to leave a trailing comma at the end, e.g. (a,) is a tuple with single element a, but (a) just resolves to whatever a is.