3👍
If you try running this in the repl, you’ll see that:
>>> BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(os.getcwd()))),
>>> BASE_DIR
('c:\\srv',)
>>> isinstance(BASE_DIR, tuple)
True
>>> os.path.join(BASE_DIR, 'templates')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\ntpath.py", line 84, in join
result_path = result_path + '\\'
TypeError: can only concatenate tuple (not "str") to tuple
>>>
the problem is the ,
at the end of
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(os.getcwd()))),
^
| this one
it works if you remove it:
>>> BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(os.getcwd())))
>>> os.path.join(BASE_DIR, 'templates')
'c:\\srv\\templates'
in Python a comma is used to create tuples (even though many people think it’s the parenthesis):
>>> 1,2,3
(1, 2, 3)
a two element tuple:
>>> 1,2
(1, 2)
and a one-element tuple:
>>> 1,
(1,)
0👍
TEMPLATE_DIR
is a list.
Change this line to
TEMPLATE_DIR = [os.path.join(BASE_DIR, 'templates')]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': TEMPLATE_DIR,
'APP_DIRS': True,
'OPTIONS':
{'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
- [Django]-Django.db.utils.OperationalError: FATAL: database does not exist (postgres / deploy to digitalocean)
- [Django]-Django ORM vs PostgreSQL raw SQL
0👍
Use a front slash(/) instead of a comma(,) in your "TEMPLATE’s DIR:
like that: 'DIRS': [(BASE_DIR / 'templates')],
- [Django]-Django model serialization returns only primary key for foreign key
- [Django]-Why .WMV files have mime type 'video/x-ms-asf' instead of 'video/x-ms-wmv'?
- [Django]-Peculiar thing about leaving the DateTimeField empty in Django?
- [Django]-Pip with virtualenv not upgrading Django
Source:stackexchange.com