DATABASE_URL- MYSQL://username:password@host:port/database_name
Error: database_name has no attributes.
if 'DATABASE_URL' in os.environ:
url = urlparse(os.getenv['DATABASE_URL'])
g['db'] = mysql.connector.connect(user=url.username,password=url.password, host=url.hostname ,port=url.port,path=url.path[1:])
First of all,
url.host
would result into:use
url.hostname
instead.To get the
database_name
out of the provided URL, usepath
:An alternative "Don't reinvent the wheel" way to approach the problem would be to use
sqlalachemy
'smake_url()
, which is regexp-based: