简体   繁体   English

如何从终端中的django app从settings.py打印BASE_DIR?

[英]How to print BASE_DIR from settings.py from django app in terminal?

How to print BASE_DIR from settings.py from django app in terminal? 如何从终端中的django app从settings.py打印BASE_DIR? i have the following code in test1.py file: 我在test1.py文件中有以下代码:

import os
import django
import settings

print BASE_DIR

but it prints error: 但它打印错误:

File "test1.py", line 5, in <module>
    print BASE_DIR
NameError: name 'BASE_DIR' is not defined

My goal is to write value of BASE_DIR to see what dir is used by Django project. 我的目标是编写BASE_DIR的值来查看Django项目使用的dir。

These commands will help: 这些命令将有助于:

python manage.py shell

Then in python shell type: 然后在python shell类型中:

from django.conf import settings
print(settings.BASE_DIR)

You should print the attribute of the imported module: 您应该打印导入模块的属性:

print settings.BASE_DIR

Or import this variable from the module: 或者从模块导入此变量:

from settings import BASE_DIR

print BASE_DIR

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM