def findSettingsModule():
    "Find the settings module dot path within django's manage.py file"
    try:
        with open('manage.py', 'r') as manage:
            manage_contents = manage.read()

            search = re.search(
                r"([\"\'](?P<module>[a-z\.]+)[\"\'])", manage_contents
            )
            if search:  # django version < 1.7
                settings_mod = search.group("module")

            else:
                # in 1.7, manage.py settings declaration looks like:
                # os.environ.setdefault(
                #     "DJANGO_SETTINGS_MODULE", "example_app.settings"
                # )
                search = re.search(
                    "\".*?\"(,\\s)??\"(?P<module>.*?)\"\\)$",
                    manage_contents, re.I | re.S | re.M
                )
                settings_mod = search.group("module")

        os.environ.setdefault('DJANGO_SETTINGS_MODULE', settings_mod)
    except IOError as e:
        msg = (
                str(e) + '\nPlease ensure that you are in the same directory '
                         'as django\'s "manage.py" file.'
        )
        raise IOError(chalk.red(msg), None, sys.exc_info()[2])
    except AttributeError:
        settings_mod = ''
    return settings_mod
def findSettingsModule ( ) : try : with open ( 'manage.py' , 'r' ) as manage : manage_contents = manage . read ( ) search = re . search ( r"([\"\'](?P<module>[a-z\.]+)[\"\'])" , manage_contents ) if search : settings_mod = search . group ( "module" ) else : search = re . search ( "\".*?\"(,\\s)??\"(?P<module>.*?)\"\\)$" , manage_contents , re . I | re . S | re . M ) settings_mod = search . group ( "module" ) os . environ . setdefault ( 'DJANGO_SETTINGS_MODULE' , settings_mod ) except IOError as e : msg = ( str ( e ) + '\nPlease ensure that you are in the same directory ' 'as django\'s "manage.py" file.' ) raise IOError ( chalk . red ( msg ) , None , sys . exc_info ( ) [ 2 ] ) except AttributeError : settings_mod = '' return settings_mod
Find the settings module dot path within django's manage.py file