Commit 2f609eef authored by Beno Sons's avatar Beno Sons

.env DB

parent 29ad9f84
...@@ -17,6 +17,12 @@ PORT=8000 ...@@ -17,6 +17,12 @@ PORT=8000
----------------------------- -----------------------------
SECRET_KEY=your-secret-key SECRET_KEY=your-secret-key
DATABASE_URL=postgresql://postgres:khansia215758@30.10.20.102/BUILDER DATABASE_URL=postgresql://postgres:khansia215758@30.10.20.102/BUILDER
DATABASE_NAME=BUILDER
DB_USERNAME=postgres
DB_PASSWORD=khansia215758
DB_HOST=30.10.20.102
DB_PORT=5432
DATABASE_SCHEMA=gen_application_31
JWT_SECRET_KEY=your-jwt-secret-key JWT_SECRET_KEY=your-jwt-secret-key
FLASK_APP=run.py FLASK_APP=run.py
FLASK_ENV=development FLASK_ENV=development
......
...@@ -6,7 +6,7 @@ load_dotenv() ...@@ -6,7 +6,7 @@ load_dotenv()
class Config: class Config:
SECRET_KEY = os.getenv('SECRET_KEY', 'mysecretkey') SECRET_KEY = os.getenv('SECRET_KEY', 'mysecretkey')
SQLALCHEMY_DATABASE_URI = os.getenv('DATABASE_URL', 'postgresql://user:password@localhost/dbname') SQLALCHEMY_DATABASE_URI = f"postgresql://{os.getenv('DB_USERNAME')}:{os.getenv('DB_PASSWORD')}@{os.getenv('DB_HOST')}:{os.getenv('DB_PORT')}/{os.getenv('DATABASE_NAME')}"
SCHEMA_NAME = os.getenv('DATABASE_SCHEMA') SCHEMA_NAME = os.getenv('DATABASE_SCHEMA')
SQLALCHEMY_TRACK_MODIFICATIONS = False SQLALCHEMY_TRACK_MODIFICATIONS = False
DEBUG = os.getenv('FLASK_ENV') == 'development' DEBUG = os.getenv('FLASK_ENV') == 'development'
......
#!/usr/bin/python #!/usr/bin/python
import psycopg2 import psycopg2
from configparser import ConfigParser from configparser import ConfigParser
from dotenv import load_dotenv
class connection(): class connection():
...@@ -59,14 +59,13 @@ class connection(): ...@@ -59,14 +59,13 @@ class connection():
try: try:
# read connection parameters # read connection parameters
conn = psycopg2.connect( conn = psycopg2.connect(
database = "BUILDER", database = os.getenv('DATABASE_NAME'),
user = "postgres", user = os.getenv('DB_USERNAME'),
password = "khansia215758", password = os.getenv('DB_PASSWORD'),
host = "103.126.28.68", host = os.getenv('DB_HOST'),
port = "8082" port = os.getenv('DB_PORT')
) )
except (Exception, psycopg2.DatabaseError) as error: except (Exception, psycopg2.DatabaseError) as error:
print(error) print(error)
finally: finally:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment