Skip to content

Commit 70eda27

Browse files
committed
Change connection string
1 parent d4d87ba commit 70eda27

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

azureproject/production.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
ALLOWED_HOSTS = [os.environ['WEBSITE_HOSTNAME']] if 'WEBSITE_HOSTNAME' in os.environ else []
77
CSRF_TRUSTED_ORIGINS = ['https://' + os.environ['WEBSITE_HOSTNAME']] if 'WEBSITE_HOSTNAME' in os.environ else []
88

9-
# Configure Postgres database; the full username for PostgreSQL flexible server is
10-
# username (not @sever-name).
9+
# Configure Postgres database based on connection string of the libpq Keyword/Value form
10+
# https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING
11+
conn_str = os.environ['AZURE_POSTGRESQL_CONNECTIONSTRING']
12+
#conn_str= 'dbname=msdocs-python-postgres-psfdj-database host=msdocs-python-postgres-psfdj-server.postgres.database.azure.com port=5432 sslmode=require user=bazbufjyde password=PASSWORD$'
13+
conn_str_params = {pair.split('=')[0]: pair.split('=')[1] for pair in conn_str.split(' ')}
14+
1115
DATABASE_URI = 'postgresql+psycopg2://{dbuser}:{dbpass}@{dbhost}/{dbname}'.format(
12-
dbuser=os.environ['DBUSER'],
13-
dbpass=os.environ['DBPASS'],
14-
dbhost=os.environ['DBHOST'] + ".postgres.database.azure.com",
15-
dbname=os.environ['DBNAME']
16+
dbuser=conn_str_params['user'],
17+
dbpass=conn_str_params['password'],
18+
dbhost=conn_str_params['host'],
19+
dbname=conn_str_params['dbname']
1620
)

0 commit comments

Comments
 (0)