I tried to make a todo application using bottle with python

The python version you are using is 3.6 It's a memorandum of my own, but I'd be happy if you could give me some advice.

Source code

todo.py


#coding:utf-8
from bottle import run,route,template,redirect,request,post
import sqlite3

@route("/")
def index():
    todo_list = get_todo()
    return template("index",todo_list=todo_list)

@route("/enter",method=["POST"])
def enter():
    todo=request.POST.getunicode("todo_list")
    #Todo to database_write list
    save_todo(todo)
    #return todo
    return redirect("/")

@route("/delete",method=["POST"])
def delete():

    conn=sqlite3.connect("todo.db")
    c=conn.cursor()

    delete="delete from todo_list where todo='{0}'".format(request.POST.getunicode("finished"))
    c.execute(delete)
    conn.commit()
    return redirect("/")

#Todo to database_save list
def save_todo(todo):
    conn= sqlite3.connect('todo.db')
    c= conn.cursor()
    insert="insert into todo_list(todo) values('{0}')".format(todo)
    c.execute(insert)
    conn.commit()

#Database todo_read list
def get_todo():
    conn= sqlite3.connect('todo.db')
    c= conn.cursor()
    select="select * from todo_list"
    c.execute(select)
    row = c.fetchall()
    return row
run(host="localhost",port=8000,debug=True,reloader=True)

index.html


<!DOCTYPE html>
<html lang="jp">
<head>
    <meta charset="UTF-8">
    <title>To Do App</title>
</head>
<body>
    <h1>Welcome to ToDo list</h1>

    <form name="todo" method="POST" action="/enter">
        <input type="text" name="todo_list"  required /><br/>
        <input type="submit" value="add to" />
    </form>


    <form method="POST" action="/delete">
      % for todo in todo_list:
      <input type="checkbox" name="finished"value="{{todo[0]}}">{{todo[0]}}<br>
      % end
      <input type="submit" value="Clear checked list">
    </form>


</body>
</html>

Impressions

It was my first time to create a web application, so I had a lot of trouble. Also, since the degree of completion is still low, I will continue to improve it. In particular, I haven't done any design, so I hope I can make it look cool.

Recommended Posts

I tried to make a todo application using bottle with python
I tried to make a 2channel post notification application with Python
I tried to make a simple mail sending application with tkinter of Python
I tried to make a stopwatch using tkinter in python
I tried to make a regular expression of "time" using Python
[3rd] I tried to make a certain authenticator-like tool with python
I tried to make a regular expression of "date" using Python
I tried to make a periodical process with Selenium and Python
[4th] I tried to make a certain authenticator-like tool with python
[1st] I tried to make a certain authenticator-like tool with python
I want to make a game with Python
I tried to make a ○ ✕ game using TensorFlow
Python: I tried to make a flat / flat_map just right with a generator
I tried to make a traffic light-like with Raspberry Pi 4 (Python edition)
I tried to discriminate a 6-digit number with a number discrimination application made with python
I tried to create a sample to access Salesforce using Python and Bottle
I want to make a web application using React and Python flask
I tried to draw a route map with Python
I tried to make an OCR application with PySimpleGUI
If you want to make a TODO application (distributed) now using only Python
[Patent analysis] I tried to make a patent map with Python without spending money
[ES Lab] I tried to develop a WEB application with Python and Flask ②
I tried to make various "dummy data" with Python faker
I tried to make GUI tic-tac-toe with Python and Tkinter
I tried to make a simple text editor using PyQt
I tried to make a real-time sound source separation mock with Python machine learning
I tried a functional language with Python
[Python] A quick web application with Bottle!
I tried to make a Web API
[Python] I tried to implement stable sorting, so make a note
[Python] A memo that I tried to get started with asyncio
[Introduction] I want to make a Mastodon Bot with Python! 【Beginners】
I tried to make a strange quote for Jojo with LSTM
I tried to make an image similarity function with Python + OpenCV
I tried to make a mechanism of exclusive control with Go
[Python] I tried to make an application that calculates salary according to working hours with tkinter
I tried to make a generator that generates a C # container class from CSV with Python
I tried to make a motion detection surveillance camera with OpenCV using a WEB camera with Raspberry Pi
I want to make a voice changer using Python and SPTK with reference to a famous site
I made a GUI application with Python + PyQt5
I tried to get CloudWatch data with Python
I tried using mecab with python2.7, ruby2.3, php7
I tried to output LLVM IR with Python
I tried reading a CSV file using Python
I tried to automate sushi making with python
I want to write to a file with Python
I tried using a database (sqlite3) with kivy
I tried to communicate with a remote server by Socket communication with Python.
I tried to create a program to convert hexadecimal numbers to decimal numbers with python
I tried to make a calculator with Tkinter so I will write it
I tried to make "Sakurai-san" a LINE BOT with API Gateway + Lambda
[AWS] [GCP] I tried to make cloud services easy to use with Python
[Streamlit] I hate JavaScript, so I make a web application only with Python
[Outlook] I tried to automatically create a daily report email with Python
I tried to build a Mac Python development environment with pythonz + direnv
[Zaif] I tried to make it easy to trade virtual currencies with Python
I tried to make a url shortening service serverless with AWS CDK
[Python] I tried to make a simple program that works on the command line using argparse.
I tried fp-growth with python
I tried to make a "fucking big literary converter"
I tried scraping with Python