如何从 django 交互式 shell 打印 TEMPLATE_DIRS 的值?

发布于 2024-12-27 08:02:29 字数 111 浏览 3 评论 0原文

我想打印这个值以用于调试目的。我该怎么做呢?

打印 TEMPLATE_DIRS 不起作用 打印设置.TEMPLATE_DIRS 不起作用。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仅此而已 2025-01-03 08:02:29

您先导入设置了吗?

$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.TEMPLATES[0]['DIRS']
Out [2] ('/Volumes/HDD/usr/local/django/mytestproject/templates',)

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.TEMPLATES[0]['DIRS']
Out [2] ('/Volumes/HDD/usr/local/django/mytestproject/templates',)
ζ澈沫 2025-01-03 08:02:29

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

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

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

然后,当您运行服务器时,这些值将在非常开始

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文