4
我一直在模仿一段时间的模板,而且我非常喜欢django体验的每一刻。然而,由于Django是这样一个大风扇松耦合,我想知道,为什么不把这段代码:的Django中的模板目录逻辑
import os
import platform
if platform.system() == 'Windows':
templateFiles = os.path.join(os.path.dirname(__file__), '..', 'templates').replace('\\','/')
else:
templateFiles = os.path.join(os.path.dirname(__file__), '..', 'templates')
TEMPLATE_DIRS = (
# This includes the templates folder
templateFiles,
)
代替:
import os
TEMPLATE_DIRS = (
templateFiles = os.path.join(os.path.dirname(__file__), '..', 'templates').replace('\\','/')
)
会不会第一个例子跟随松散耦合的理念比第二个更好(我相信它),如果是这样,为什么django默认为第二个代码示例,而不是第一个?
对不起,我的默认到第二。我真的不知道为什么,在这里运行django 1.5。 – 2013-04-05 11:07:34
当你运行'django-admin.py startproject mysite'时,它会复制一个模板项目布局,并且在1.5中[settings.py的源代码在这里](https://github.com/django/django/blob/稳定/ 1.5.x的/ Django的/ conf目录/ project_template/PROJECT_NAME/settings.py)。也许你有一个本地补丁?或者你从其他地方获得项目模板? – 2013-04-05 11:16:44
我相信是这样的,我的python安装与做事的方式有些不同。感谢防弹版本,它看起来很酷。 – 2013-04-05 11:19:52