Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Template Directory Path

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?

like image 898
enadun Avatar asked Jun 20 '13 08:06

enadun


1 Answers

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.

like image 111
enadun Avatar answered Nov 01 '22 09:11

enadun