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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With