How can I print the value of TEMPLATE_DIRS from the django interactive shell?

一个人想着一个人 提交于 2019-12-07 11:54:18

问题


I would like to print this value for debugging purposes. How can I do it?

print TEMPLATE_DIRS doesn't work print settings.TEMPLATE_DIRS doesn't work.


回答1:


Did you import the settings first?

$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:


I think the easiest, and therefore the ans you may be looking for is to add the following to your settings.py

print ("This is the template.dirs", TEMPLATES[0]['DIRS'])...python 3.x for 2.x leave out the parentheses

so the answer is... standard way to access dict element within a list TEMPLATES[0]['DIRS']

Then when you run your server the values will be printed out, at the very beginning



来源:https://stackoverflow.com/questions/8885541/how-can-i-print-the-value-of-template-dirs-from-the-django-interactive-shell

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