Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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? i have the following code in test1.py file:

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.

like image 977
user1406647 Avatar asked Jan 25 '15 11:01

user1406647


2 Answers

These commands will help:

python manage.py shell

Then in python shell type:

from django.conf import settings
print(settings.BASE_DIR)
like image 142
Yurii Halapup Avatar answered Oct 15 '22 13:10

Yurii Halapup


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
like image 27
catavaran Avatar answered Oct 15 '22 15:10

catavaran