Created
October 30, 2024 17:33
-
-
Save jonasbjork/971be8d8ec196b9e149ac99ef0ba4fe5 to your computer and use it in GitHub Desktop.
Ett exempel: TODO-applikation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
import sqlite3 | |
app = Flask(__name__) | |
def init_db(): | |
with sqlite3.connect('todo.db') as conn: | |
cursor = conn.cursor() | |
cursor.execute('''CREATE TABLE IF NOT EXISTS todos ( | |
id INTEGER PRIMARY KEY AUTOINCREMENT, | |
title TEXT NOT NULL, | |
completed BOOLEAN NOT NULL CHECK (completed IN (0, 1)) | |
)''') | |
conn.commit() | |
init_db() | |
@app.route('/todo', methods=['POST']) | |
def create_todo(): | |
return "None" | |
@app.route('/todo', methods=['GET']) | |
def get_todos(): | |
return "None" | |
@app.route('/todo/<int:todo_id>', methods=['PUT']) | |
def mark_completed(todo_id): | |
return "None" | |
@app.route('/todo/<int:todo_id>', methods=['DELETE']) | |
def delete_todo(todo_id): | |
return "None" | |
if __name__ == '__main__': | |
app.run(debug=True) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment