Django tuple checking: TEMPLATE_DIRS should be tuple?

两盒软妹~` 提交于 2019-12-11 02:27:05

问题


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


回答1:


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.




回答2:


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

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


来源:https://stackoverflow.com/questions/24340746/django-tuple-checking-template-dirs-should-be-tuple

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!