Skip to content Skip to sidebar Skip to footer

Os.path Python Module Not Working In Heroku

I am building a django app on heroku and facing a lot of trouble with os.path module. My project is unable to find the templates on heroku while its working perfectly on localhost.

Solution 1:

Technically os.path will be pointing to "project/project" because that's where settings.py is located. Try moving your "templates" directory there. It worked for me!

Just make sure to change templateDir to the following:

    templateDir = os.path.dirname(__file__) 
    TEMPLATE_DIRS = (
    os.path.join(templateDir, "templates"),

Solution 2:

Something like the following worked for me on similar Heroku/MEDIA_ROOT issue.

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
)

BASE_PATH = os.path.dirname(__file__)
TEMPLATE_DIRS = (
    os.path.join(BASE_PATH, "project/templates/templates"), 
)

However, if you stuck to the default directory structure for Django, you would not have to set TEMPLATE_DIRS at all. Ie, home.html should be at project/project/templates. Typically css/javascript is outside that directory. I can verify that this works on Heroku.

Solution 3:

One of the small difference between Windows & *inx systems is, file naming. Windows, winDows, windows, windowS represents the same file under windows but not in Linux.

This is the problem I faced with Heroku (probably, its on *inx). So, I had to use exact folder names in TEMPLATE_DIRS.

this is the correct.

templateDir = os.path.join(os.path.join(os.path.split(currDir)[0], "templates"), "Templates")

the previous one is:

templateDir = os.path.join(os.path.join(os.path.split(currDir)[0], "templates"), "templates")

Post a Comment for "Os.path Python Module Not Working In Heroku"