Skip to content

Commit 243e8f3

Browse files
authored
Merge pull request #6 from souovan/python-flask
Python flask
2 parents 5527790 + aaeec08 commit 243e8f3

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

python-flask/src/.gitinore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
__pycache__/
2+
venv/

python-flask/src/app.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import logging
2+
from flask import Flask, jsonify
3+
from flask_sqlalchemy import SQLAlchemy
4+
5+
app = Flask(__name__)
6+
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
7+
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://postgres:password@localhost/postgres'
8+
app.debug = True
9+
db = SQLAlchemy(app)
10+
11+
class users(db.Model):
12+
__tablename__ = 'usuario'
13+
id_usuario = db.Column(db.String(), primary_key=True)
14+
fk_id_categoria_usuario = db.Column(db.String(), nullable=False)
15+
login = db.Column(db.String(), nullable=False)
16+
senha = db.Column(db.String(), nullable=False)
17+
18+
def __init__(self, id_usuario, fk_id_categoria_usuario, login, senha):
19+
self.id_usuario = id_usuario
20+
self.fk_id_categoria_usuario = fk_id_categoria_usuario
21+
self.login = login
22+
self.senha = senha
23+
24+
25+
@app.route('/test', methods=['GET'])
26+
def test():
27+
return {
28+
'test': 'test1'
29+
}
30+
31+
# A simple test for the db connection
32+
@app.route('/test_db_connection', methods=['GET'])
33+
def test_db_test_db_connection():
34+
all_users = users.query.all()
35+
output = []
36+
for usuario in all_users:
37+
current_user = {}
38+
current_user['id_usuario'] = usuario.id_usuario
39+
current_user['fk_id_categoria_usuario'] = usuario.fk_id_categoria_usuario
40+
current_user['login'] = usuario.login
41+
current_user['senha'] = usuario.senha
42+
output.append(current_user)
43+
return jsonify(output)
44+

python-flask/src/requirements.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
click==8.0.3
2+
Flask==2.0.2
3+
Flask-SQLAlchemy==2.5.1
4+
greenlet==1.1.2
5+
itsdangerous==2.0.1
6+
Jinja2==3.0.3
7+
MarkupSafe==2.0.1
8+
psycopg2-binary==2.9.2
9+
SQLAlchemy==1.4.27
10+
Werkzeug==2.0.2

0 commit comments

Comments
 (0)