Django tuple checking: TEMPLATE_DIRS should be tup

2019-07-22 03:18发布

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!!

2条回答
兄弟一词,经得起流年.
2楼-- · 2019-07-22 03:43

Try This Should Work , It Works For Me All The Times

TEMPLATE_DIRS = os.path.join(BASE_DIR , 'templates')
查看更多
做个烂人
3楼-- · 2019-07-22 04:00

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.

查看更多
登录 后发表回答