0% found this document useful (0 votes)
4 views1 page

Crud React Python

insertion , update, delete in python

Uploaded by

rollandsiuol
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Crud React Python

insertion , update, delete in python

Uploaded by

rollandsiuol
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

from flask import Flask, request, jsonify

import psycopg2

app = Flask(__name__)

# Connexion à la base de données PostgreSQL


def get_db_connection():
conn = psycopg2.connect(
host="localhost",
database="VPN_DB",
user="your_db_user",
password="your_db_password"
)
return conn

@app.route('/api/users', methods=['POST'])
def register_user():
data = request.get_json()

username = data.get('Nom_User')
email = data.get('Email_User')
password = data.get('MotDePass_User')

if not username or not email or not password:


return jsonify({'error': 'Tous les champs sont requis'}), 400

conn = get_db_connection()
cursor = conn.cursor()

try:
cursor.execute(
"INSERT INTO clientVpn_User (Nom_User, Email_User, MotDePass_User) VALUES (%s, %s, %s)",
(username, email, password)
)
conn.commit()
return jsonify({'message': 'Utilisateur ajouté avec succès'}), 201
except Exception as e:
return jsonify({'error': str(e)}), 500
finally:
cursor.close()
conn.close()

if __name__ == '__main__':
app.run(debug=True)
Tyg

You might also like