Template Directory Path

11,029

To fix this error:

File "/home/myUser/path/to/project/projectName/projectName/settings.py", line 116, in <module>
  os.path.join(BASE_DIR, 'templates')
NameError: name 'os' is not defined

I had to add this line at the beginning of settings.py:

import os

Then I get this error:

File "/home/myUser/path/to/project/projectName/projectName/settings.py", line 116, in <module>
  os.path.join(BASE_DIR, 'templates')
NameError: name 'BASE_DIR' is not defined

To fix this, I added this line to settings.py:

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

This will return the current file path. You might need to change the os.path.join(BASE_DIR, 'templates') part accordingly.

Share:
11,029
enadun
Author by

enadun

Updated on August 15, 2022

Comments

  • enadun
    enadun almost 2 years

    I'm new to python. I'm using python 2.7.1 with django 1.5.1.

    When I put this code:

    TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]

    in my settings.py, the terminal shows the following error:

    File "/home/pipo/Desktop/mysite/mysite/settings.py", line 116, in <module>
        [os.path.join(BASE_DIR, 'templates')]
    NameError: name 'os' is not defined
    

    Can someone tell me the reason for this error?