python – TemplateDoesNotExist in / for a compiled Django project using PyInstaller

I am trying to run a Django project using an EXE file compiled using Pyinstaller. But when I run the compiled .EXE file using this command I get TemplateDoesNotExist at /.

dj.exe runserver localhost:8000

I first installed Pyinstaller using the command:

pip install pyinstaller

Then i installed OSGeo4W64 on my Windows 10 machine to GDAL.

I added this in settings.py:


import os


if os.name == 'nt':
    import platform
    OSGEO4W = r"C:OSGeo4W"
    if '64' in platform.architecture()(0):
        OSGEO4W += "64"
    assert os.path.isdir(OSGEO4W), "Directory does not exist: " + OSGEO4W
    os.environ('OSGEO4W_ROOT') = OSGEO4W
    os.environ('GDAL_DATA') = OSGEO4W + r"sharegdal"
    os.environ('PROJ_LIB') = OSGEO4W + r"shareproj"
    os.environ('PATH') = OSGEO4W + r"bin;" + os.environ('PATH')

os.environ('DJANGO_SETTINGS_MODULE') = 'dj.settings'

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

TEMPLATE_DIRS = (
    os.path.join(SETTINGS_PATH, 'templates'),
)

GEOS_LIBRARY_PATH = r'C:OSGeo4W64bingeos_c.dll'
GDAL_LIBRARY_PATH = r'C:OSGeo4W64bingdal204.dll'

I also generated a specification file using this command:

pyi-makespec dj/manage.py

And this is the one generated manage.spec:

# -*- mode: python ; coding: utf-8 -*-

block_cipher = None


a = Analysis(('dj\manage.py'),
             pathex=('C:\Users\omen\Desktop'),
             binaries=(),
             datas=(('app/templates','app/templates')),
             hiddenimports=(),
             hookspath=(),
             runtime_hooks=(),
             excludes=(),
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          (),
          exclude_binaries=True,
          name='manage',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               upx_exclude=(),
               name='manage')

I added in datas the template folder but it didn't work …

Please help!!!