【问题标题】:How can I print the value of TEMPLATE_DIRS from the django interactive shell?如何从 django 交互式 shell 打印 TEMPLATE_DIRS 的值?
【发布时间】:2012-02-11 17:17:47
【问题描述】:

我想打印此值以进行调试。我该怎么做?

print TEMPLATE_DIRS 不起作用 print settings.TEMPLATE_DIRS 不起作用。

【问题讨论】:

    标签: django django-settings django-shell


    【解决方案1】:

    您是否先导入设置?

    $steve ./manage.py shell
    
    Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05)
    
    In [1]: from django.conf import settings
    In [2]: settings.TEMPLATE_DIRS 
    Out [2] ('/Volumes/HDD/usr/local/django/mytestproject/templates',)
    

    【讨论】:

    【解决方案2】:

    我认为最简单的方法,因此您可能正在寻找的答案是将以下内容添加到您的 settings.py

    print ("This is the template.dirs", TEMPLATES[0]['DIRS'])...python 3.x for 2.x 省略括号

    所以答案是...访问列表 TEMPLATES[0]['DIRS'] 中的 dict 元素的标准方法

    然后当你运行你的服务器时,这些值会在一开始就被打印出来

    【讨论】:

      猜你喜欢
      • 2017-07-15
      • 1970-01-01
      • 2023-03-22
      • 2014-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-12
      相关资源
      最近更新 更多