页面思考
- 数据都是存在数据库里面的,查询笔记就是通过检索数据库内容,然后在页面展示
代码实现
import streamlit as st
from datetime import datetime
import pymysql
import pandas as pd
st.write("# 新增笔记")
st.write("### [查询笔记](http://localhost:8501/czklist) ||[删除笔记](http://localhost:8501/czklist)")
text_1 = st.text_input('标题')
text_2 = st.text_area('内容')
if st.button('提交'):
current_time = datetime.now()
current_time_str = current_time.strftime("%Y-%m-%d %H:%M:%S")
st.write(current_time_str)
conn = pymysql.connect(
host="",
port=46,
user="",
password="",
database="czk")
cursor = conn.cursor()
query ="INSERT INTO czkbook (found_time, headline, main_body) VALUES (%s, %s, %s)"
values = (current_time_str, text_1, text_2)
cursor.execute(query, values)
conn.commit()
cursor.close()
conn.close()
st.write("## 新增成功")
(新人练习项目,欢迎大佬指教)