Forums

I'm getting a wrong absolute path on Django, but getting the right path when on ./manage.py shell

from future import unicode_literals import os from six.moves.configparser import SafeConfigParser from os import path from . import settings

import logging

def get_config_path(filename): return path.abspath("issue_tracker/config/{}".format(filename))

def config_for_environment(environment): env_filename = "%s.ini" % environment env_path = get_config_path(env_filename) print(env_path)

logging.error(env_path + ' not found!')

config = read_config(env_path)
return config

def read_config(config_file): config = SafeConfigParser() config.read(config_file)

return config

environment = settings.DEFAULT_ENVIRONMENT

sys_config = config_for_environment(environment)

all = [ sys_config, environment ]

IT IS VERY WEIRD

WHAT I GET WHEN THE DJANGO APP is running: /home/zorexsalvo/issue_tracker/config/development.ini

WHAT I GET WHEN I'M IN './manage.py shell': /home/zorexsalvo/bits/issue-tracking-system/issue_tracking/issue_tracker/config/development.ini

issue_tracker/config/ is a relative path that is relative to the current working directory. Don't use relative paths like that because you'll never be sure where it's starting from. There are some hints here for how to handle paths more reliably.