What is the absolute path of BASE DIR?

absolute path example
base_dir path __file__ ancestor 3
django get base dir in view
how to write a file path
relative path
absolute path vs relative path linux
os.path.join(base_dir 'templates')
python get directory from path

Django newbie here. I have trouble understanding the meaning of:

BASE_DIR = os.path.dirname(os.path.dirname(__file__))


STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static')
    os.path.join(os.path.dirname(BASE_DIR), "static", "static"),

What's happening here?

I take it the "file" is the settings.py file we are in (?), so the BASE_Dir is two folders up from that...? i.e. the one with manage.py in it?

So the STATIC_ROOT, will be one? or two? directories up from the BASE_DIR. Will the STATIC_ROOT FOLDER be made for me? Or do I have to make one called "static"?

    ├── BASE_DIR
    │   ├── MY_APP
    │   │   └── settings.py
    │   └── manage.py
    └── static

Is the above right for this example? Then what the heck / where the heck will the STATIC_FILES_DIRS be?

If you want to know where is located BASE_DIR, you can print it to the terminal, just add this line to your settings.py:

print "base dir path", BASE_DIR

and runserver to see results.

Path (computing), As result, the first is an absolute path from the root directory of drive C:, path from a relative path and the base path (the current directory) that� An absolute path name. An absolute path name containing the $PKGINSTconstruction, which means always install to a base directoryderived from the package instance. Note –. If the pkgaddcommand is called with the argument -a none, it always asks the administrator for a base directory.

BASE_DIR is your Django project directory. The same directory where manage.py is located.

Relative and absolute paths, in the file system and on the web , An absolute file path describes how to access a given file or directory, starting from the root of the file system. A file path is also called a pathname. Relative file � In noder path.isAbsolute('\\\folder\test.txt')evaluates to true. But I guess that the path you are using is not consider an absolute path hence resulting in an exception in this piece of ESLint code from path-util.js:

If your settings.py is configured like this, your filesystem looks like this:

    ├── BASE_DIR
    │   ├── MY_APP
    │   │   └── settings.py
    │   └── manage.py
    └── static        -> STATIC_ROOT
        └── static    -> STATICFILES_DIRS

But it is not a good configuration because it mixes up collected statics and the directory where Django tries to find static files (e. g. to collect them). May be better to use this:

    └── BASE_DIR
        ├── my_app
        │   ├── settings.py
        │   └── static              -> STATICFILES_DIRS
        ├── manage.py
        └── deployment
            ├── collected_static    -> STATIC_ROOT
            └── media               -> MEDIA_ROOT

# settings.py
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
STATICFILES_DIRS = (os.path.join(
    BASE_DIR, "my_app", "static"),)
STATIC_ROOT = os.path.join(
    os.path.dirname(BASE_DIR), "deployment", "collected_static")
MEDIA_ROOT = os.path.join(
    os.path.dirname(BASE_DIR), "deployment", "media")

Now you can easily deploy your static and media files using your favorite webserver (Apache, Nginx etc.) pointing it to the "deployment" directory.


I added also a recommendable configuration for MEDIA_ROOT and changed the path for the collected static.

File path formats on Windows systems, Base.Filesystem.pwd — Function. pwd() -> AbstractString. Get the current If you want to get absolute paths back, call readdir with an absolute directory path� What is the absolute path of BASE DIR? (2) Django newbie here. I have trouble understanding the meaning of:

for path settings in django projects i use

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_PRODUCTION_DIR = os.path.abspath(os.path.join(
os.path.dirname(__file__), '..', '..', 'static_production'))

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(STATIC_PRODUCTION_DIR, "static")

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(STATIC_PRODUCTION_DIR, "media")

   os.path.join(BASE_DIR, "static"),

How do I interact with files in Python?, In this case, the value is interpreted as the current directory. Return Values �. Returns the canonicalized absolute pathname on success. The resulting path will � BASE_DIR = os.path.dirname(os.path.dirname(__file__)) Because there's no abspath, you can get different results for BASE_DIR depending on how settings.py is run. This is an edge case, since settings.py is almost always imported by django in the right context, but still -- compare:

What I did and that really helped me was :

  1. go to settings.py and add --> STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')] at the end of file.

  2. Go to the base html template in your templates folder, and add these 2 lines in the head section (Just make sure you create a folder in static. in my case it is css as you can see below, could be different name ):

    a){% load static %} b)

Filesystem � The Julia Language, Given a string containing the path of a file or directory, this function will return the For example, if a script called 'database.init.php' which is included from� Depending on your server configuration, getting correct path information can be challenging. For example, PHP does not provide a variable that will return the the base URL of your site. To help out, you can use the following code snippets to get the absolute path, document root, and base URL, respectively. Get the absolute path

realpath - Manual, Joins an absolute directory with a relative filename. Similar to join/2, Equivalent to basedir(PathType, Application, #{}) or basedir(PathsType, Application, #{}). An absolute path is defined as the specifying the location of a file or directory from the root directory (/). In other words we can say absolute path is a complete path from start of actual filesystem from / directory. Some examples of absolute path: /var/ ftp /pub /etc /samba.smb.conf /boot/grub/grub.conf

dirname - Manual, Absolute file paths begin with the directory separator "/" (or with a drive specification on Windows). Returns the complete base name of the file without the path. Replaces #788 with my review and changes and rebase. This adds a basedir option at compile time that parallels the filename option to allow paths starting with / to be treated as relative to the basedir rather than the current file.

Erlang -- filename,

  • Here: docs.python.org/2/library/… get the abs path of the base directory of the application. Rest i guess you can figure out.
  • thanks, and what do I do with os.path.dirname(path)?
  • It is getting the absolute path of the directory again, which I believe you already have in BASE_DIR
  • ok. err, thanks. Possibly stellar information, but way over my head.
  • Brilliant! Thank you django11. That would solve many of my problems.
  • In the current Django version, the command should be: print ("base dir path", PROJECT_ROOT)
  • @Dror Which version are you referring to ?? I just checked it in Django 1.10 and it is working fine.
  • @Cody the "print" command is python's. I was using python 3.5.X
  • short, simple and neat
  • Brilliant! Thanks so much Norman. May your loins be fruitfull.
  • That tree diagram was super useful!
  • should MEDIA_ROOT be under BASEDIR or under MY_APP ?