I have Docker Containers application with Flask and Django containers. It is possible share Database between Django container and Flask Container?
django: &django
...
depends_on:
- postgres
flask:
...
ports:
- "5090:5090"
...
- postgres
links:
- postgres
postgres:
build:
...
env_file:
- ./.envs/.local/.postgres
Models are in Django application. So, I need to do a Login in Flask Application using Postgres Database. The problem is, I only want to use the connection to Database, I do not need to do models in Flask.
I used Sqlalchemy method:
if form.validate_on_submit():
query = session.query(User)
login = User.query.filter(username=form.username.data).first()
if login is not None:
print(login)
return redirect(url_for('index'))
return render_template('login.html', form=form)
And I tried with Panda method:
if form.validate_on_submit():
sql = "SELECT * from users WHERE username = '{0}'".format(form.username.data)
login = pd.read_sql_query(sql,SQLALCHEMY_DATABASE_URI)
if login is not None:
print(login)
return redirect(url_for('index'))
But the error is the same in both cases, I need to do a relation, so, it is a Migration, in Flask.
**sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedTable) relation "users"**
It is my database.py:
...
SQLALCHEMY_DATABASE_URI = 'postgres://%s:%s@%s:%s/%s' % (user, pwd, host, port, db)
SQLALCHEMY_TRACK_MODIFICATIONS = os.environ.get('SQLALCHEMY_TRACK_MODIFICATIONS')
db_session = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=engine))
def init_db():
...