Lerndatenbank/lernplattform/routes.py

21 lines
659 B
Python
Raw Normal View History

2024-08-05 20:43:29 +02:00
from flask import render_template, url_for, flash, redirect, jsonify
from lernplattform import app
from lernplattform.models import User
@app.route('/')
def index():
# Render the main page with the list of users
return render_template('index.html')
@app.route('/users', methods=['GET'])
def get_users():
users = User.query.all()
return jsonify([user.username for user in users])
@app.route('/users', methods=['POST'])
def create_user():
data = request.get_json()
new_user = User(username=data['username'], email=data['email'])
db.session.add(new_user)
db.session.commit()
return jsonify({'message': 'User created'}), 201