-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
24 lines (19 loc) · 768 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import os
import urllib.parse
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
# Configure the database connection using environment variables
sqlalchemy_database_uri = f"mysql://{os.environ['DB_USER']}:{urllib.parse.quote_plus(os.environ['DB_PASSWORD'])}@{os.environ['DB_HOST']}/{os.environ['DB_NAME']}"
print(f'sqlalchemy_database_uri {sqlalchemy_database_uri}')
app.config['SQLALCHEMY_DATABASE_URI'] = sqlalchemy_database_uri
db = SQLAlchemy(app)
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True)
@app.route('/')
def hello():
return "Hello, Flask in Docker!"
if __name__ == '__main__':
db.create_all()
app.run(host='0.0.0.0', port=5000)